Originally posted by kaushik banerjee:
hi,
the foll piece of code when run does not display any of the buttons.i was expecting button bc. however if the order of the layout managers is reversed,the code gives the standard output,ie buttons are displayed in flow layout.why is this so
Ths in advance.
import java.awt.*;
public class layout
{
public static void main(String[] a)
{
Frame f = new Frame("Layout");
Button bn=new Button("North");
Button bs=new Button("South");
Button be=new Button("East");
Button bw=new Button("West");
Button bc=new Button("Center");
FlowLayout fl=new FlowLayout();
f.setLayout(fl);
f.add(bn);
f.add(bs);
f.add(be);
f.add(bw);
f.add(bc);
f.validate();
f.setLayout(new BorderLayout());
f.pack();
f.setVisible(true);
f.setSize(250,250);
}
}
Regards,
kaushik
Originally posted by David Freels:
You changed your layout from flow to border and did not re-add the components using the new constraints.
David
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Adds the specified component to the end of this container. Also notifies the layout manager to add the component to this
container's layout using the specified constraints object.
Adds the specified component to the layout. Not used by this
class.
Adds the specified component to the layout, using the specified
constraint object. For border layouts, the constraint must be one of the following constants: NORTH, SOUTH, EAST, WEST, or CENTER.
Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
Won't you be my neighbor? - Fred Rogers. tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|