Differences between JFrame setVisible (false) and setState (Frame.ICONIFIED)
In Swing, we can hide JFrame
with two methods:
-
frame.setVisible(false)
-
frame.setState(Frame.ICONIFIED)
The difference I found is:
-
frame.setVisible(false)
removes the icon from the taskbar when itICONIFIED
doesn't work. - We can add a listener to
ICONIFIED
, whereas we cannot add one toframe.setVisible(false)
.
Is there another significant difference that I am not seeing? Any ideas would be greatly appreciated.
source to share
The main differences I know are as follows:
1) frame.setState (Frame.ICONIFIED) just changes the state of the frame, whereas frame.setVisible (false) changes the visibility of the frame.
2) setState (Frame.ICONIFIED) method in java.awt.Frame class can minify frame programmatically and setState (Frame.NORMAL) to restore it.
3) An invisible frame cannot use a listener, but you can add a listener to a frame that is ICONIFIED.
4) frame.setVisible (false) removes the physical state of the frame from the screen, whereas setState (Frame.ICONIFIED) just changes state while preserving its physical state.
These two methods have their own characteristics, so be more confident in choosing the one that works best for your situation.
source to share
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 it ICONFIED
does the window minimization process.
source to share