Working with 2 or more frames(使用 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.
这篇关于使用 2 个或更多帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 2 个或更多帧


- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 转换 ldap 日期 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01