Nikhil
Nikhil

Reputation: 109

Java Swings GUI, changing the display based on which button is clicked. What is the ideal way to implement this?

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:

enter image description here

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

Answers (1)

dic19
dic19

Reputation: 17971

Although this is a primarily opinion-based answer I'd go with a Nested Layout approach:

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

Related Questions