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 Java version 1.1 or later 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 (Graphic User Interface) 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 Java version 1.1 or later 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.
available on the web at:
optional Replicator mirror
Please email your feedback for publication, letters to the editor, errors, omissions, typos, formatting errors, ambiguities, unclear wording, broken/redirected link reports, suggestions to improve this page or comments to Roedy Green : . If you want your message, your name or email kept confidential, not considered for public posting, please explicitly specify that. Unless you state otherwise, I will treat your message as a letter to the editor that I may or may not publish in the feedback section. After that, it will be too late to retract it. If you disagree with something I said, especially when sending an ad-hominem attack, a rant composed mainly of obscenities or a death threat, please quote the offending passage and cite the web page where you found it, tell me why you think it is wrong, and, if possible, provide some supporting evidence. I can’t very well fix erroneous or ambiguous text if I can’t find it.
Your face IP:[184.108.40.206]
|Feedback||You are visitor number 69,907.|