Swing layout is done wrong
Hello,
I have a custom JPanel which represents a simple chat user interface.
With userlist, messages and input.
Here is the code so far:
Code:
public class ChatPanel extends JPanel{
private JTextArea ta_chat;
private JList l_users;
private JScrollPane sp_chatscroll, sp_listscroll;
private JTextField tf_chatenter;
private Vector<String> m_userlist;
public ChatPanel(){
ta_chat = new JTextArea(20,50);
m_userlist = new Vector<String>();
l_users = new JList(m_userlist);
tf_chatenter = new JTextField();
initView();
}
private void initView(){
this.setLayout(new GridBagLayout());
ta_chat.setAutoscrolls(true);
ta_chat.setLineWrap(true);
ta_chat.setEditable(false);
ta_chat.setFocusable(false);
sp_chatscroll = new JScrollPane(ta_chat);
GridBagConstraints formatter = new GridBagConstraints();
formatter.anchor = GridBagConstraints.FIRST_LINE_START;
formatter.gridx = 0;
formatter.gridy = 0;
this.add(sp_chatscroll, formatter);
l_users.setVisibleRowCount(20);
l_users.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
sp_listscroll = new JScrollPane(l_users);
formatter.gridx = 1;
this.add(sp_listscroll, formatter);
tf_chatenter.setColumns(65);
formatter.gridx = 0;
formatter.gridy = 1;
formatter.fill = GridBagConstraints.HORIZONTAL;
this.add(tf_chatenter, formatter);
}
}
As you can see, I am using a GridBagLayout to layout the components.
However, they are not being lain out as I want them to.
This is how it looks like:
http://img256.imageshack.us/img256/4...iledlayout.png
I want the list, which is on the right, to be next to the textarea and additionally over the right part of the textfield, like you have it in generic chat UIs.
Can anyone help me?