0

Hi everyone,

I'm trying to build a GUI for a project I'm working on, and I'm having trouble working out how to move between different displays within the same GUI.

I have a simple GUI with a menu bar and two buttons in the content pane. If the user clicks button A, I'd like for the user to move to a different content pane or GUI (not sure which is better) with the same menu bar, much like how a user moves between webpages in a browser.

So far I've managed to have it so that when the user clicks button A, a whole new GUI is displayed, but this isn't exactly what I want.

Any ideas on how to go about this? I'm sure it's pretty basic but I haven't managed to find anything on this so far. Thanks in advance!

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by jiraiya
0

Take a look the CardLayout layout manager.
It displays one component at a time.
You can set this as the layout manager of the main panel of the JFrame.
You can then create a separate JPanel for each "page" of your GUI and show the appropriate "page" when user clicks a button.
I think that the documentation can explain it better then I can.
http://java.sun.com/docs/books/tutorial/uiswing/layout/card.html

Edited by sergb: n/a

0

Thanks sergb!

Using the CardLayout class sorted it out quite nicely.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.