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

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.

? Explain James Cherrill please? I don't know wtf you're saying...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.