Ale*_*eks 0 java swing combobox render
您好,我有以下问题:
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();
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,我正在做一个非常简单的例子.如果我取消注释标记的部分,则不显示标签项.如果我调整窗口大小,它们会再次可见.这里奇怪的是我甚combo至没有添加到面板或任何地方.我只是在实例化它.有人能告诉我为什么我需要调整框架大小以查看标签吗?难道我做错了什么?
| 归档时间: |
|
| 查看次数: |
992 次 |
| 最近记录: |