Search code examples
javaswinguser-interfacejframejcomponent

JFrame window with sub components


So I have created this JFrame window which has a lot of items like JLabel, JComboBox JTextField etc… At the bottom it has a "next" JButton.

I want that when a user clicks the next button, everything on the screen should be removed and replaced with stuffs from other class that I have created.

I only manage to open a new JFrame window whenever I click the next button. Can somebody please tell me how to remove all items from the screen and replace them with items from another class.

Thanks. I am a newbie so please give me the easiest way possible.


Solution

  • This sounds like a job for CardLayout

    You could create a base panel in the BorderLayout.SOUTH position of your JFrame that would have your navigation buttons and have a number of panels added to your main panel being managed by CardLayout.

    See Creating Wizard Dialogs with Java Swing