I'm not sure if this has been answered or the correct way of phrasing it, but have had no luck in my search. I have 4 JFrame guis all in their own classes: a main gui and 3 others. I want to know if it is possible to display the other guis inside the same window without opening a new window and setting the first window to a false visibility? I'm able to call the other JFrames and make them display through a series of actionlisteners, but they open another window, making me have to setVisible(false) the gui window. I want to be able to have all the guis display in the same window without opening/closing windows. Thanks
Asked
Active
Viewed 4,930 times
1 Answers
4
You should not be creating separate frames. Just create separate panels and swap the panels.
See the Swing tutorial on How to Use Card Layout for more information.
Also, if you ever do need more than one window, you should be using a JDialog for the child windows. An application should only have a single JFrame.

camickr
- 321,443
- 19
- 166
- 288
-
Thanks. I was looking at cardlayout but wasn't sure if there was a different approach. – TechnicalCustoms Jun 17 '13 at 03:37
-
I'm still not understanding how to use cardlayout with my code. The demo they give is of no help as my classes already have buttons implemented in them and uses buttons to switch between the "cards". – TechnicalCustoms Jun 17 '13 at 04:55
-
11) For an example with buttons to change between cards, see this [short example](http://stackoverflow.com/a/5786005/418556). 2) See also [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) for many other options besides `CardLayout` (e.g. `JTabbedPane`). – Andrew Thompson Jun 17 '13 at 05:25