• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Layout manager help needed

 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats great. Thanks a lot
 
There are no more "hours", it's centi-days. They say it's better, but this tiny ad says it's stupid:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic