Difference between show() and setVisible()

asukai
asukai used Ask the Experts™
on
Can anyone tell me the difference between show() and setVisible()? Do show() and setVisible(true) have the same effect? Would it be stupid to have code like

frame.setVisible(true);
frame.show();

?

and for setVisible(false) and hide()?

Only difference I can think of is that setVisible can able to make components visible depending on its parameter.

asukai
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
show() is a method inherited from Window class and makes the window displayable

setVisible(boolean) is defined on a component and shows or hides the component.

Since JFrame is a subclass of Window which in turn is a subclass of Component you could use both but individually speaking and view it from the class point, they have different purpose.

vemul
Mick BarryJava Developer
Top Expert 2010

Commented:
There is no difference in functionality, all setVisible(true) does is call show().
Ovi

Commented:
The only difference is that the method is inherited from the Component class and there is deprecated and suggested replacement is setVisible(boolean).
Mick BarryJava Developer
Top Expert 2010

Commented:
show()/Hide() are not deprecated for top level window classes such as Frame, Dialog etc.

Also didn't mention above that all setVisible(false) does is call hide().

So you can use either setVisible() or show()/hide() for your top level windows and your application will function the same.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial