本文介绍了使用 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?

推荐答案

除了 CardLayoutJFrame 与多个 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.

  1. JDesktopPane/JInternalFames (啧啧).
  2. JSplitPane (Tut.).
  3. JTabbedPane (Tut.).
  4. JLayeredPane,如果你觉得勇敢的话 (啧啧.).
  5. JToolBar - 如果需要可浮动 (啧啧.).
  6. 嵌套布局JPanel的不同约束/a>.
  1. JDesktopPane/JInternalFames (Tut.).
  2. JSplitPane (Tut.).
  3. JTabbedPane (Tut.).
  4. JLayeredPane, if you're feeling brave (Tut.).
  5. JToolBar - floatable if needed (Tut.).
  6. 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 怎么办?

可能将它们组合为子菜单.

Possibly combine them as sub-menus.

这篇关于使用 2 个或更多帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!