Search code examples
javaswingwindow

Java Swing - Multiple control sets in one window


Is it possible to create something like a loading phase (contains progressbar and label etc.) then after loading is done switch to next phase with different controls like button etc. without creating a new Window for each of the phases? I know I could probably do this using panels and changing their visibility but if they all overlaped it would be really hard to add or edit the controls. I want to create a game and it would be really annoying if a new window opened almost everytime user did something. (example Main menu -> Shop -> Back to main menu etc.)


Solution

  • There are two ways to do this: Static and dynamic

    The static way is easier, and you can accomplish it using a CardLayout. The dynamic way would require you to create methods for each screen change, which would clear all previous content and insert the appropriate controls.

    http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html