0

Hi folks.

I'm making a GUI. It contains multiple JPanels. I'm having trouble making contents of other JPanels (than the first/main JPanel; others are subclasses to the first one) visible...

From the first JPanel, I call a draw method to a second JPanel. This second JPanel's draw method displays a text, and that's OK, but it's not showing the following thing where a button should be created.

The first JPanel displays everything (text, buttons...).


1. What's going on? Why can't I have buttons in my second JPanel??

2. Any tips on making a GUI that can have switchable screens? (e.g. I click on button of one screen, that takes me to another screen...) Other approaches would be appreciated.


Cheers

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by thompsonSensibl
0

Make each screen an independent JPanel and use a common "data" object to hold all the values that are displayed or entered via the panels. The panels use the data objects get methods to retrieve the info to display in their constructors, and the set methods to update the object when the user clicks OK. Each panel can chain to the next by simply instatiating a new instance of the next panel (passing the data object as a parameter) then calling its own dispose() method.
You shouldn't need "draw" methods unless you are doing something unusual.

Edited by JamesCherrill: n/a

This topic has been dead for over six months. 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.