I am making a GUI for a Java application. What I am trying to do is have a frame, and based on user actions change the panel being displayed. Although if I do something like this :
private void setFrameContent(Container content) {
appFrame.setContentPane(content);
}
the frame will just freeze once I try to change the JPanel being displayed. Also tried some variations on this.
How should I change the content of the frame?
One option would be CardLayout but that would mean I would have to create all the panels on app startup while some of them might not be used. What other ways are there to achieve this?
1) if you add
JComponentto the already visible Container, then you have to call forrevalidate()andrepaint(), in your casefor Java7 is there implemeted
revalidate()andrepaint()toJFramedirectlyfor Jav6 and lower version you have to
revalidate()andrepaint()forContentPane2) I think that CardLayout (still) could be better options for switching betweens
Viewsin Swing GUI