I have about 3 frames in my java swing application. What it the correct way how to handle with these frames? I mean some pattern or something else. Now I have always one class which represent frame and one class for panel which is main in this frame. Now I have defined frames as static variable and when I wanna hide them I call
classname.frameName.setVisible(false);
is this the correct solution?
Besides the (excellent) suggestions of a CardLayout
or JFrame
with multiple JDialog
instances, here are some other strategies which might work singly or in combination, to collapse a variety of content panes into a single frame.
JDesktopPane
/JInternalFames
(Tut.). JSplitPane
(Tut.). JTabbedPane
(Tut.).JLayeredPane
, if you're feeling brave (Tut.).JToolBar
- floatable if needed (Tut.).JPanel
in a nested layout.There are probably more..
Of course, as Adamski pointed out, there are some further quirks to consider..
What if each frame has JMenuBars or JMenus?
Possibly combine them as sub-menus.
Take a look at a decent docking framework such as MyDoggy. This allows you to display all three components in a single JFrame
, but is very flexible in that you can view the data side-by-side, resize and maximise components.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With