tags:

views:

51

answers:

2

I have 2 panels, the first one is the menu, and the second is the application main panel. Firstly the menu panel shows up, than i need to switch to the other panel if a specific button is pressed on the menu (the menu is hidden but the app returns to it after running is completed). && i need to resize the frame too if it's possible.

can i do this somehow?

+2  A: 

Normally, this would be a job for a CardLayout, but if you want the frame to resize, you'll have to remove the menu panel from it and add the main panel instead, then call pack().

Michael Borgwardt
invalidate() won't resize the frame. pack() must be called on the frame for that.
jfpoilpret
@jfpoilpret: right - fixed
Michael Borgwardt
i see this solution can work, but i don't know how the panel can access to the frame wihout cardlayout (to access JFrame.pack())
bog
@bog: um... by holding a reference to it?
Michael Borgwardt
+1  A: 

You can use card layout.Or else set panel1.setVisible(false) when you want to view Panel2.In the same way set panel2.setVisible(false) when you want to view Panel1.

Arivu2020