Creating a GUI with multiple panels and one frame

12,831

Solution 1

Yes, the best way is to use a CardLayout of which there's a great tutorial (please see the link), and many examples online including in this very forum, several of which I've written, including:

Solution 2

JTabbedPane is already implemented for you!
JTabbedPane's tutorial.

Share:
12,831
neilb
Author by

neilb

Updated on June 04, 2022

Comments

  • neilb
    neilb almost 2 years

    I am trying to create a simple GUI. I have a menu bar that is filled with various JMenuItems. Each menu item should link to a different "window". Currently, I am thinking the best way to do this is to create a single frame, and create various JPanels. My ActionListeners will toggle visibility of the different panels, and only one panel should be visible at a time. Is this the best way to go about the task? Or is there a better workaround.