Nested gridlayout problems

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Didje
    New Member
    • Sep 2007
    • 2

    Nested gridlayout problems

    Hi,
    I am trying to create a grid which contains three rows, within each row there will be various buttons also in gridlayout.
    There are 20 buttons in the middle row, 3 in the top and 4 at the bottom. I want the top and bottom buttons to be of comparable size to the buttons in the centre row. However, each row of the gridlayout is the same size so, as a result, the top and bottom buttons are huge and the central ones are squeezed. I don't know how to fix it. Here is the code I've got. Any help would be appreciated:
    import java.awt.*;

    public class NestedPanel extends Frame {
    public NestedPanel(Str ing title) {
    super(title);
    setLayout(new GridLayout(3,1, 0,40));
    addPanel1();
    addPanel2();
    addPanel3();
    }
    public void addPanel1() {
    Panel panel = new Panel();
    panel.setLayout (new GridLayout(0,3, 15,0));
    panel.add(new Button("TButton X"));
    panel.add(new Button("TButton Y"));
    panel.add(new Button("TButton Z"));
    add(panel);
    }
    public void addPanel2() {
    Panel panel = new Panel();
    panel.setLayout (new GridLayout(4,5) );
    for(int i=1;i<=20;i++)
    {
    panel.add(new Button("Button " + i));
    }
    add(panel);
    }
    public void addPanel3() {
    Panel panel = new Panel();
    panel.setLayout (new GridLayout(0,4, 15,30));
    panel.add(new Button("BButton X"));
    panel.add(new Button("BButton Y"));
    panel.add(new Button("BButton Z"));
    panel.add(new Button("BButton Q"));
    add(BorderLayou t.SOUTH,panel);
    }
    public static void main(String[] args) {
    NestedPanel abc =
    new NestedPanel("Ne sted Panel");
    abc.setSize(350 , 550);
    abc.setVisible( true);
    }
    }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    As you already noticed a Gridlayout allows equal space to all of its components.
    Have a look at the new SprintLayout class instead. The API page for this
    class even has a link to a Java Tutorial on exactly this layout manager.

    kind regards,

    Jos

    Comment

    Working...