简体   繁体   English

JFrame setVisible(false)和setState(Frame.ICONIFIED)之间的差异

[英]Differences between JFrame setVisible(false) and setState(Frame.ICONIFIED)

In Swing, we can hide JFrame by using two methods: 在Swing中,我们可以使用两种方法隐藏JFrame

  1. frame.setVisible(false)
  2. frame.setState(Frame.ICONIFIED)

The difference that I discover are: 我发现的不同之处是:

  1. frame.setVisible(false) removes icon from taskbar whereas ICONIFIED doesn't. frame.setVisible(false)从任务栏中删除图标,而ICONIFIED则不删除。
  2. We can add listener to ICONIFIED whereas we can't add it for frame.setVisible(false) . 我们可以将侦听器添加到ICONIFIED而我们不能为frame.setVisible(false)添加它。

Is there other major difference I'm missing? 我还缺少其他重大差异吗? Any ideas would be greatly appreciated. 任何想法将不胜感激。

With setVisible(false), if the Component is not already marked invisible, setVisible calls invalidate() which invalidates the Container's layout and the chain of parents since there is now more screen real estate in the Container and the positions of the siblings must be adjusted to flow into the freed space.

API of Component . 组件的API

But the ICONFIED is doing the minimize process of a window. ICONFIED正在进行窗口的最小化处理。

We can add listener to ICONIFIED whereas we can't add it for frame.setVisible(false). 我们可以将侦听器添加到ICONIFIED,而我们不能为frame.setVisible(false)添加它。

You can use a ComponentListener and handle componentHidden(...) . 您可以使用ComponentListener并处理componentHidden(...)

The major differences as I know are as follows: 我所知的主要差异如下:
1) frame.setState(Frame.ICONIFIED) just changes the state of the frame whereas frame.setVisible(false) changes visibility of frame. 1)frame.setState(Frame.ICONIFIED)只改变帧的状态,而frame.setVisible(false)改变帧的可见性。
2) setState(Frame.ICONIFIED) method in class java.awt.Frame can programmatically minimize a frame and setState(Frame.NORMAL) to restore it. 2)类java.awt.Frame中的setState(Frame.ICONIFIED)方法可以以编程方式最小化帧和setState(Frame.NORMAL)以恢复它。
3) Invisible frame cannot use any listener but you can add listener to frame that is ICONIFIED. 3)不可见的帧不能使用任何监听器,但您可以将监听器添加到ICONIFIED的帧。
4) frame.setVisible(false) removes the physical state of frame from screen whereas setState(Frame.ICONIFIED) just changes state preserving its physical state. 4)frame.setVisible(false)从屏幕上删除帧的物理状态,而setState(Frame.ICONIFIED)只是改变保持其物理状态的状态。

These two methods have their own characteristics so be more confident in choosing one that is more suitable for your situation. 这两种方法各有特色,因此更有信心选择更适合您情况的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JFrame过渡效果 - 当调用setState(Frame.ICONIFIED)时,它只会进入没有动画的任务栏 - JFrame transition effect - when called setState(Frame.ICONIFIED) it just goes to Taskbar without animation 使用setVisible打印JFrame(false) - Print JFrame with setVisible(false) 无法设置JFrame的可见(false) - Unable to setVisible(false) of JFrame 调用setVisible(假); 来自JFrame内部 - setVIsible(false); from within JFrame JFrame getContentPane.removeAll()仅在.setVisible(false)和.setVisible(true)之间工作 - JFrame getContentPane.removeAll() only working between a .setVisible(false) and .setVisible(true) 如何使用setVisible(false)从JFrame创建图像? - How to create an image from a JFrame with setVisible(false)? setVisible(false)时JFrame不会隐藏 - JFrame does not hide when setVisible(false) 当JFrame最小化setState(JFrame.ICONIFIED)时,但是当用户从任务栏还原事件时,该事件写入事件代码 - when a JFrame is minimized setState(JFrame.ICONIFIED) but where to write to code of event when user restores it from taskbar 加载其他jframe类时,如何设置setvisible(true)我有setvisible(false)的JFrame? - how to setvisible(true) a JFrame which i had setvisible(false) when loading other jframe class? 即使frame为setVisible,也无法设置Undecorated(false) - Can't SetUndecorated even if frame is setVisible(false)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM