您好,我有以下問題:的Java JComboBox中引起呈現問題
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
添加到面板或任何地方。我只是實例化它。 有人能告訴我爲什麼我需要調整框架大小以查看標籤嗎?難道我做錯了什麼?
那麼解決它,thx – Aleks