With setVisible( true ), if the Component is not already marked visible, setVisible calls invalidate() which invalidates the Container’s layout and the chain of parents since there is now less screen real estate in the Container and the positions of the siblings must be adjusted to squeeze in this new Component.
Further setVisible will schedule a repaint if the visibility status actually changed. However, it won’t schedule the Container.validate() automatically. That is up to you to do after all your visibility changes to the Components are done.
show() unhides a component by marking it as visible, allowing it to be painted again on the next painting cycle. show is deprecated. With JDK 1.1+ you are supposed to use setVisible( true);
A Component is considered visible if in on any repainting cycle, it should be repainted. It might not actually be visible on the screen right now because it is occluded, or because CardLayout is not currently displaying the panel in which the component lives.
How are invisible elements treated?
setVisible has no effect on the visibily flags of the children. Unlike some GUI programming systems, when you parent.setVisible( true ) you don’t disturb any of the children’s visibility flags, and the hidden children will stay hidden, even when you again reveal the parent.
Unlike ordinary Components, Windows, Frames and JFrames conveniently start out life automatically with setVisible( false ). Traditionally you do the validate() and setVisible( true ) in the code that calls the Frame’s constructor not in the Frame’s constructor or addNotify method.
hide() make temporarily invisible. hide is deprecated. With JDK 1.1+ you are supposed to use setVisible( false); instead. hide is also used to describe what one window does to another when it is painted over top of it.
![]() |
and suggestions to improve this page to Roedy Green : | ||
| Canadian Mind Products | |||
| mindprod.com IP:[65.110.21.43] | |||
| Your face IP:[38.103.63.62] | The information on this page is for non-military use only. | ||
| You are visitor number 27,585. | Military use includes use by defence contractors. | ||
| You can get a fresh copy of this page from: | or possibly from your local J: drive (Java virtual drive/mindprod.com website mirror) | ||
| http://mindprod.com/jgloss/setvisible.html | J:\mindprod\jgloss\setvisible.html | ||