This is the snippit im having a problem with. I've tried playing with the preferred size of both the JList and the JScrollPane with no luck/mixed results.
I want to be able to size it to exactly 1 size so it never changes.
import java.awt.BorderLayout;
import javax.swing.DefaultListModel;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
public class plat extends JFrame {
JList users;
DefaultListModel listModel;
public static void main(String[] args){
SwingUtilities.invokeLater(new Runnable() {
public void run(){
new plat();
}
});
}
public plat() {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel topPanel = new JPanel();
JTextArea chatArea = new JTextArea(10, 20);
chatArea.setEditable(false);
listModel = new DefaultListModel();
users = new JList(listModel);
users.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
users.setLayoutOrientation(JList.VERTICAL);
topPanel.add(new JScrollPane(chatArea));
topPanel.add(new JScrollPane(users));
this.add(topPanel, BorderLayout.NORTH);
//listModel.addElement("HI");
//listModel.addElement("MY");
//listModel.addElement("TRY");
this.pack();
this.setVisible(true);
}
}
The JTextArea on the left I'm able to size using rows/cols options in the constructor. I want the JScrollPane for the JList to be a fixed width and match the height of the JTextArea.
Any suggestions?