I have a JPanel (panelOne) on a JFrame (frame). On the panelOne I have two buttons and I like to, If I pushing one button the JPanel will change to another. But how? I can't access the frame from panelOne.
Asked
Active
Viewed 91 times
1 Answers
1
You have access to the whole tree of components from a Component.
See Java/Swing: Obtain Window/JFrame from inside a JPanel to get the top most ancestor. Also have a look at the Component javadoc: http://docs.oracle.com/javase/7/docs/api/java/awt/Component.html
-
Thanks, I got the Frame. But how can I change the JPanel? – Roberto Sep 09 '14 at 08:35
-
Have a look at the javadoc : http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html#setContentPane(java.awt.Container) – cghislai Sep 09 '14 at 08:37