File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Do you always need setVisible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Do you always need setVisible?" Watch "Do you always need setVisible?" New topic
Author

Do you always need setVisible?

Kourosh Keshavarzi
Ranch Hand

Joined: Oct 23, 2000
Posts: 66
Do you only need the setVisible when you don't have
a layout manager.
Same with setBounds and setSize.
Does the layout manager take care
of that stuff for you?
Do yo have to setBounds and setSize or one is enought?
What purpose does te method show() have.
do you use it instead of setvisible.
My book uses it in its code but doesn't have any kind
of definition or anything.
thanks is advance
Kourosh
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
setVisible, setBounds and setSize are all methods inherited from the Component Class. They will get default settings if you don't set them (false for setVisible and 0,0 for setBounds).
I am not sure if setSize can replace setBounds.
If you are running an Applet the size can be set in the HTML.
show() is deprecated but also from component.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Subha Guhan
Greenhorn

Joined: Nov 06, 2000
Posts: 23
Also it is required only for top level components like window, frames etc. for components like buttons,textfields etc it is not a requirement to specify it.
Kourosh Keshavarzi
Ranch Hand

Joined: Oct 23, 2000
Posts: 66
Thanks Cindy and Subha.
Koursh
Aparna Narayanan
Ranch Hand

Joined: Nov 07, 2000
Posts: 44
Hi,
One more addition...
setBounds(int x,int y, int width, int height) is used for Moving as well as Resizing a component
setSize(int width, int height) is only for resizing the component
So, setSize cannot replace setBounds in some cases.
Aparna
Sudha Kris
Ranch Hand

Joined: Oct 31, 2000
Posts: 46
Correct me if I am wrong, but I think if you don't use a Window or a Frame. ie if you use an Applet you don't need to set it visible. I mean you don't have to do setVisible(true).
Sudha
 
 
subject: Do you always need setVisible?