【发布时间】:2011-11-29 08:43:07
【问题描述】:
您好,我有以下问题:
public class TestCombo extends JFrame{
public TestCombo() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200,200);
setVisible(true);
setLayout(new BorderLayout());
JPanel panel = new JPanel();
panel.setLayout(new GridLayout(2,4));
JLabel l1 = new JLabel("test1");
JLabel l2 = new JLabel("test2");
panel.add(l1);
panel.add(l2);
// JComboBox<String> combo = new JComboBox<String>();// <-- uncomment this for the problem
this.add(panel, BorderLayout.NORTH);
}
public static void main(String[] args) {
new TestCombo();
}
}
如您所见,我正在做一个非常简单的示例。如果我取消注释标记的部分,则不会显示标签项。如果我调整窗口大小,它们会再次可见。这里奇怪的是,我什至没有将combo 添加到面板或任何地方。我只是在实例化它。
有人能告诉我为什么我需要调整框架大小才能看到标签吗?我做错了吗?
【问题讨论】:
标签: java swing combobox render