使用2个或更多帧 [英] Working with 2 or more frames

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

推荐答案

除了<$ c $的(优秀)建议c> 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.


  1. JDesktopPane / JInternalFames Tut。)。

  2. JSplitPane Tut。)。

  3. JTabbedPane Tut。)。

  4. JLayeredPane ,如果你有勇气( Tut。)。

  5. JToolBar - 如果需要可浮动( Tut。)。

  6. JPanel 的不同约束https://stackoverflow.com/questions/5621338/about-swing-and-jtable/5630271#5630271\">布局

  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.

可能还有更多..

当然,正如亚当斯基指出的,还有一些进一步的怪癖要考虑..

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个或更多帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆