PDA

View Full Version : GridLayout Java


Aonlan
10-21-2005, 01:07 AM
okay I am trying to make a Java Applet and using gridlayout

here's the code:


setLayout(new GridLayout(2,2));
ButtonA = new Button("A");
ButtonB = new Button("B");
ButtonC = new Button("C");
ButtonD = new Button("D");

add(ButtonA,"1");
add(ButtonB,"2");
add(ButtonC,"3");
add(ButtonD,"4");


unfortunately, this code makes all the buttons stretch towards the whole screen that's 400x400, what if i want to make it in the middle that's 200x200 on a 400x400 applet.

brad211987
10-21-2005, 04:57 AM
I dont remember much about different layouts but you could probably put the four buttons on a JPanel (call it class ButtonPanel) or whatever with its size 200 by 200. And then add the panel to the applet using borderlayout.CENTER. Do just like you have been for the panel, using grid layout and let them stretch the whole size of the panel.

kalium
10-25-2005, 01:00 PM
Gridlayout will take the number of components you add and, in the layout specified in its construct, will fill the canvas. Maybe you should use a BorderLayout as suggested, or prehaps a GridbagLayout.