Reputation: 109
I'm pretty new to programming Java based GUI applications. Here's what I have in mind, I want to divide the window into two areas. The first are contains buttons (or a list), and based on which button was clicked, or which item was selected, the second area changes. (finite number of buttons) Something like this:
I can think of many ways to do this, but I am not sure what is the best practice. Do I have several invisible panels and make only 1 panel visible at a time, or do I change the ordering (bring panel x to front), or is there some other way?
Appreciate any help I receive!! Thanks in advance!
Upvotes: 0
Views: 283
Reputation: 17971
Although this is a primarily opinion-based answer I'd go with a Nested Layout approach:
Main panel with BorderLayout. Or you can use the frame's content pane which already has BorderLayout
as default layout manager.
Left panel with BoxLayout (or GridBagLayout).
Right panel with CardLayout.
Note: Buttons in the left panel should switch right panels cards.
See Lesson: Layoing Out Components within a Container tutorial.
For complex GUIs you have also third-party layout managers available, listed in this answer:
Upvotes: 4