I am using a JList in Java Swing, but when my Dialog opens, the List isn't shown.
private JList getJList() {
if (mylist == null) {
mylist = new JList();
mylist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mylist.setSize(new Dimension(154, 106));
model.addElement("test");
model.addElement("zwei");
mylist.setVisible(true);
}
return mylist;
}
The list is defined:
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJList(), BorderLayout.CENTER);
}
return jContentPane;
}
It's a JContentPane (/Panel)
public fensterdrei(Frame owner) {
super(owner);
initialize();
}
the code calling getJContentPane()
:
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("Auswahl");
}
I can't find where you are setting the model of the JList?
Something like
mylist = new JList();
mylist.setModel(model);
Please have a look at the Code Conventions for the Java Programming Language
FensterDrei
instead of fensterdrei
myList
instead of mylist
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With