Hello peeps.
I have the following in 1 JFrame:
main menu with at least 1 start / stop button + the title in the middle.
Upon pressing start my "game" would start by showing another frame basicly. But inside this JFrame offcourse.
I currently do this as followed:
1xJFrame with in it 1 contentPane(borderlayout)
In the center of the borderlayout i place a JPanel (name: centerPanel, default flowlayout)
in this centerPanel i place my gamePanel and menuPanel. And dependant on where i am in my "game" i put the required panels visible/invisible.
Works nicely but i suppose they(=other developers) do it in another way because this would require that all frames are allready loaded and present, but they are just invisible. And because i'm planning to use quite some images there will be quite some unneeded ram allocated for this.
I have tried to only load the stuff i need when i actually need it. So upon starting only the menupanel shows. And when i click start i do centerPanel.removeAll( ). Then set the layout again and add everything from the gamePanel, but that doesn't work very good.
First of all the layout won't apply. It always shows in the topleft and ignores my gridbaglayout's centering stuff. (the gridbaglayout is applied to the centerPanel, and i add this layout again after removeAll() )
2nd of all. The content doesn't show up by doing a repaint. It only shows upon resizing the screen / mnimizing and opening again.
So does anyone know how it should be done and is willing to give a little example with 1 button. Upon clicking -> removing everything from the frame and displaying something else..:confused:
multiple "frames" in 1 JFrame
Started by wim DC, Aug 15 2010 09:31 AM
2 replies to this topic
#1
Posted 15 August 2010 - 09:31 AM
|
|
|
#2
Posted 15 August 2010 - 06:26 PM
"The content doesn't show up by doing a repaint."
Try revalidate().
Try revalidate().
#3
Posted 16 August 2010 - 02:50 AM
Thank you very much. The revalidate shows the new changes correctly and i fixed the layoutProblem by not doing removeAll() but remove(gamePanel) or menuPanel, then setting gamePanel/menuPanel to null.
And after that a revalidate of the centerPanel brings up the changes + a repaint of the JFrame is still required because it would still show parts of the gamePanel when i go back to the menu as the gamePanel is bigger than the menuPanel.
Thanks Sinipull :)
And after that a revalidate of the centerPanel brings up the changes + a repaint of the JFrame is still required because it would still show parts of the gamePanel when i go back to the menu as the gamePanel is bigger than the menuPanel.
Thanks Sinipull :)


Sign In
Create Account


Back to top









