使用 2 个或更多帧
我的 java swing 应用程序中有大约 3 个帧.如何处理这些帧的正确方法是什么?我的意思是某种模式或其他东西.现在我总是有一个类代表框架,一个类代表这个框架中的主要面板.现在我已将帧定义为静态变量,当我想隐藏它们时,我调用classname.frameName.setVisible(false);
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?
推荐答案
除了 CardLayout
或 JFrame
与多个 JDialog
实例,这里有一些其他策略可以单独或组合使用,以将各种内容窗格折叠到单个框架中.
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
(啧啧).JSplitPane
(Tut.一个>).JTabbedPane
(Tut.).JLayeredPane
,如果你觉得勇敢的话 (啧啧.).JToolBar
- 如果需要可浮动 (啧啧.).- 嵌套布局
JPanel
的不同约束/a>.
JDesktopPane
/JInternalFames
(Tut.).JSplitPane
(Tut.).JTabbedPane
(Tut.).JLayeredPane
, if you're feeling brave (Tut.).JToolBar
- floatable if needed (Tut.).- Different constraints of a
JPanel
in a nested layout.
可能还有更多..
当然,正如 Adamski 指出的那样,还有一些其他的怪癖需要考虑..
Of course, as Adamski pointed out, there are some further quirks to consider..
如果每个框架都有 JMenuBars 或 JMenus 怎么办?
What if each frame has JMenuBars or JMenus?
可能将它们组合为子菜单.
Possibly combine them as sub-menus.
相关文章