aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Layout manager help needed 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 "Layout manager help needed" Watch "Layout manager help needed" New topic
Author

Layout manager help needed

natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
Hi,
In the following code I get different effects for placing setSize() function at places 1 and 2.
import java.awt.*;

class winframe extends Frame{
public static void main(String[] argS){

Frame f = new Frame();

// f.setSize(400,400); //1
f.add(new Button("North"));
f.add(new Button("South"));
f.setLayout(new FlowLayout());

f.setVisible(true);
f.setSize(400,400); //2

}

}
If setSize() is at 1, i get the buttons aligned in the center at the top of frame (expected behavior from a Flow Layout!!)
but if i put it at 2, i get the buttons aligned in the left of the frame. Can anyone explain this behavior?. There must be some BorderLayout funda too behind this.
TIA

Sun Certified Programmer for Java 2 Platform
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
i can explain why this happens. If you don't place a size first but last what happends is this the original size of the window is tiny so the buttons get to be placed in the center by this behaviour. But if size is first specified the window is already having dimension so the buttons have more space to spread out. Try this code without any size and drag the window down you will see. Drag it down.
import java.awt.*;

class winframe extends Frame{
public static void main(String[] argS){
Frame f = new Frame();
//f.setSize(400,400); //1
f.add(new Button("North"));
f.add(new Button("South"));
f.setLayout(new FlowLayout());
f.setVisible(true);
//f.setSize(400,400); //2
}
}

Val SCJP <BR>going for SCJD
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
Thats great. Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Layout manager help needed