0

I want to position the JPanel that contains the send button and the textfield (and right now uses a flowlayout) at the bottom of the JTextArea (The white area). How can I achieve this?

public GUI()
{
    mainWindow = new JFrame("Chat GUI");
    lowerPanel = new JPanel(new FlowLayout());
    usersPanel = new JPanel(new GridLayout(GRIDLAYOUT_ROWS, GRIDLAYOUT_COLS));
    users = new JList(data);
    usersPanel.add(users);

    sendButton = new JButton("Send");           
    textField = new JTextField(TEXTFIELD_WIDTH);
    textArea = new JTextArea(TEXTAREA_HEIGHT, TEXTAREA_WIDTH);
    textArea.setEditable(false);
}

private void addButtonListener(JButton b) {
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

        }
    });
}

public void createGUI() {

    addButtonListener(sendButton);

    lowerPanel.add(sendButton);
    lowerPanel.add(textField);

    mainWindow.add(users);
    mainWindow.add(textArea);
    mainWindow.add(lowerPanel);

    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainWindow.setVisible(true);
    mainWindow.setLayout(new FlowLayout());
    mainWindow.pack();
}

enter image description here

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user1960836
  • 1,732
  • 7
  • 27
  • 47

1 Answers1

1

You Will have Layout :

this.add(buttonPanel,BorderLayout.SOUTH);

see this answer

Community
  • 1
  • 1
user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62