How to add a “console” like a window to a GUI?

I created a graphical interface. It has several buttons. I would like to add a console as an object below them, in which I could write messages so that the user sees them. which element / object / class should be used? I want it to be able to pass messages on different lines. here is my code for creating a GUI:

public ssGUI() {
    setLayout(new BorderLayout());

    bRunNoAdj = new JButton("Run no adjustment");
    bRunNoAdj.setVerticalTextPosition(AbstractButton.CENTER);
    bRunNoAdj.setHorizontalTextPosition(AbstractButton.LEADING);
    bRunNoAdj.setMnemonic(KeyEvent.VK_E);
    bRunNoAdj.addActionListener(this);
    bRunNoAdj.setEnabled(false);
    bRunNoAdj.setBackground(Color.white);

    bRunAdj = new JButton("Run adjustment");
    bRunAdj.setVerticalTextPosition(AbstractButton.CENTER);
    bRunAdj.setHorizontalTextPosition(AbstractButton.LEADING);
    bRunAdj.setMnemonic(KeyEvent.VK_E);
    bRunAdj.addActionListener(this);
    bRunAdj.setEnabled(false);
    bRunAdj.setBackground(Color.white);

    bConnect = new JButton("Connect");
    bConnect.setMnemonic(KeyEvent.VK_E);
    bConnect.addActionListener(this);
    bConnect.setEnabled(true);
    bConnect.setBackground(Color.white);

    bDisconnect = new JButton("Disconnect");
    bDisconnect.setMnemonic(KeyEvent.VK_E);
    bDisconnect.addActionListener(this);
    bDisconnect.setEnabled(false);
    bDisconnect.setBackground(Color.white);

    bStationary = new JButton("Show Stationary");
    bStationary.setMnemonic(KeyEvent.VK_E);
    bStationary.addActionListener(this);
    bStationary.setEnabled(false);
    bStationary.setBackground(Color.white);

    bMoving = new JButton("Show Moving");
    bMoving.setMnemonic(KeyEvent.VK_E);
    bMoving.addActionListener(this);
    bMoving.setEnabled(false);
    bMoving.setBackground(Color.white);

    JPanel topPanel = new JPanel();
    topPanel.add(bConnect);
    topPanel.add(bDisconnect);
    add(topPanel, BorderLayout.NORTH);
    JPanel centerPanel = new JPanel();
    centerPanel.add(bRunNoAdj);
    centerPanel.add(bRunAdj);
    add(centerPanel, BorderLayout.CENTER);
    JPanel bottomPanel = new JPanel();
    bottomPanel.add(bStationary);
    bottomPanel.add(bMoving);
    add(bottomPanel, BorderLayout.SOUTH);
}

Any help would be appreciated, thanks.

+4
source share
3 answers

The easiest may be to use JTextArea.

You could prevent the user from editing the area, this can be done as follows:

JTextArea area = new JTextArea();
area.setEditable(false);

, , JScrollPane :

JTextArea area = new JTextArea();
JScrollPane scrollableArea = new JScrollPane(area);

, :

area.setText(area.getText() + "\n" + newLine);

:

area.append("\n" + newLine);

, :)

+6

JTextArea. text_area.setEditable(false); , .

+5

I think you mean JTextArea or JTextField

0
source

All Articles