It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes awt - what does pack( ) do here? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "awt - what does pack( ) do here?" Watch "awt - what does pack( ) do here?" New topic
Author

awt - what does pack( ) do here?

srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
can any body pls explain :
1)what does pack() do here below??
2)my ans is as,borderlayout is the default mgr for frames,the 3 buttons will appear in center one on other,the top position occupied by three,am i right???
import java.awt.*;
public class FrameTest extends Frame {
public FrameTest() {
add (new Button("First"));
add (new Button("Second"));
add (new Button("Third"));
pack();
setVisible(true);
}
public static void main(String args []) {
new FrameTest();
}
}


please use the [code][/code] tags when showing code. visit <a href="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
Jyotsna Clarkin
Ranch Hand

Joined: Jan 26, 2001
Posts: 158
Originally posted by srinivas bolloju:
my ans is as,borderlayout is the default mgr for frames,the 3 buttons will appear in center one on other,the top position occupied by three,am i right???
[/B]

Compiling and executing you code should tell you if you are right or not
srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
but what does pack( ) do here?
thanx in adv
Albert Gray
Ranch Hand

Joined: Mar 06, 2001
Posts: 43
Hi Sriniva,
It'd be more than obvious if you compile and run your code with and without pack(). In short, this pack() is a real world packing. Answer to yourself - why do you pack your things up?!!!?
Albert

Originally posted by srinivas bolloju:
can any body pls explain :
1)what does pack() do here below??
2)my ans is as,borderlayout is the default mgr for frames,the 3 buttons will appear in center one on other,the top position occupied by three,am i right???
import java.awt.*;
public class FrameTest extends Frame {
public FrameTest() {
add (new Button("First"));
add (new Button("Second"));
add (new Button("Third"));
pack();
setVisible(true);
}
public static void main(String args []) {
new FrameTest();
}
}

Jyotsna Clarkin
Ranch Hand

Joined: Jan 26, 2001
Posts: 158
Originally posted by srinivas bolloju:
but what does pack( ) do here?
thanx in adv

Sorry forgot to answer this. pack() will ensure that the layout of the (contained) subcomponents is correct.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: awt - what does pack( ) do here?
 
Similar Threads
From JONH hunts mock exam
layout
actual GUI question on a job technical interview
pack()
Frame