2012-03-30 70 views

回答

4

取而代之的是,你怎麼樣用一個適當的佈局經理(例如CardLayout)?這將使您能夠輕鬆地在同一個容器中切換視圖。

+2

我從來沒有使用過CardLayout。我會看看我能做什麼。 – 2012-03-30 13:17:11

+2

另一個例子,請參閱[這個答案](http://stackoverflow.com/a/5786005/418556)。另請參閱[使用多個JFrames,好/壞實踐?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice/9554657#9554657)鏈接給出了兩個適用於不同用例的替代方案。 – 2012-03-30 14:00:11

1

添加事件偵聽到ComboBox和公正處理該事件,以生成新的JFrame

+0

謝謝你的建議 – 2012-03-30 13:15:54

2

添加ActionListenerJComboBox

JComboBox combo = new ... 
combo.addActionListener(new ActionListener() { 
    public void actionPerformed(ActionEvent e) { 
    // This code runs when an item is selected in the combo. 
    JFrame frm = new ... 
    frm.setVisible(true); 
    } 
}); 
+0

謝謝你的建議。 – 2012-03-30 13:15:38

相關問題