我在MainFraim中有一個主JPanel target
,而另一個currentView
JPanel已添加到target
面板。 target
面板包含帶聽衆的按鈕。然後,這些聽衆都應該改變的curretView
面板的內容,這表現如下:將JPanel更改爲另一個JPanel不重繪該更改
private JPanel currentPanel;
public void setView(String type) {
if (type.equals("overall")) {
this.currentPanel = getOverallView();
frame.setTitle("BookingCalendar - Overall View");
frame.validate();
} else if (type.equals("guest")) {
this.currentPanel = getGuestView();
frame.setTitle("BookingCalendar - Room View");
frame.validate();
} else if (type.equals("room")) {
currentPanel.removeAll();
this.currentPanel = getRoomView();
frame.setTitle("BookingCalendar - Guest View");
frame.validate();
}
}
每一個方法我稱之爲每次調用時返回新JPanel:
JPanel currentPanel = new JPanel(new MigLayout("","20 [grow, fill] 10 [grow, fill] 20", "20 [] 10 [] 20"))
的問題是,每當我稱之爲這些方法,面板不會改變。它始終保持不變(默認:getOverallView()
)
我已經嘗試使用無效,驗證,重新繪製框架,以及面板,但沒有更改發生。有人請詳細說明我需要做什麼才能完全更改面板的內容。currentView
您是不是忘記將面板添加到組件層次結構中? –