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.


8 Years
Discussion Span
Last Post by thompsonSensibl

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.