Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Layout manager help needed

 
natarajan meghanathan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
}
}
 
natarajan meghanathan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats great. Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic