我在
Java Swing中使用JList,但是当我的Dialog打开时,List没有显示.
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;
}
列表定义如下:
private JPanel getJContentPane() {
if (jContentPane == null) {
jContentPane = new JPanel();
jContentPane.setLayout(new BorderLayout());
jContentPane.add(getJList(), BorderLayout.CENTER);
}
return jContentPane;
}
这是一个JContentPane(/ Panel)
public fensterdrei(Frame owner) {
super(owner);
initialize();
}
调用getJContentPane()的代码:
private void initialize() {
this.setSize(300, 200);
this.setContentPane(getJContentPane());
this.setTitle("Auswahl");
}