[英]Differences between JFrame setVisible(false) and setState(Frame.ICONIFIED)
In Swing, we can hide JFrame
by using two methods: 在Swing中,我们可以使用两种方法隐藏
JFrame
:
frame.setVisible(false)
frame.setState(Frame.ICONIFIED)
The difference that I discover are: 我发现的不同之处是:
frame.setVisible(false)
removes icon from taskbar whereas ICONIFIED
doesn't. frame.setVisible(false)
从任务栏中删除图标,而ICONIFIED
则不删除。 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.
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.