Gridbaglayout - mysterious spaces

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

    #1

    Gridbaglayout - mysterious spaces

    Hi,
    I'm trying to design a kind of calculator GUI using gridbaglayout.
    At the top of the calculator will be a couple of menus and then will come the section with all the buttons etc.
    Initially, I have designed the menu titles purely as labels (since I haven't figured out how to create actual menus - any help there would be great!) but the final menu item is separated by a mysterious space from the other ones.
    Here is the code I've got so far - the "About" label is appearing far to the right of the other labels.

    LayoutExample window = new LayoutExample() ;
    window.setTitle ("Layout Example Application");
    window.pack();
    window.setVisib le(true);

    public LayoutExample()
    {
    //setLayout(new GridLayout(1,2) );

    p2 = new Panel();
    p2.setBackgroun d(Color.gray);
    add(p2);
    gridBag();
    }

    public void gridBag()
    {
    // Set up GridBagConstrai nts and layout and apply it to the panel
    GridBagConstrai nts c = new GridBagConstrai nts();
    GridBagLayout gridbag = new GridBagLayout() ;
    p2.setLayout(gr idbag);

    // Create the labels and add them to the panel
    Label top = new Label("File");
    top.setAlignmen t(Label.CENTER) ;
    gridbag.setCons traints(top, c);
    p2.add(top);

    Label top2 = new Label("Edit");
    top2.setAlignme nt(Label.CENTER );
    gridbag.setCons traints(top2, c);
    p2.add(top2);

    Label top3 = new Label("View");
    top3.setAlignme nt(Label.CENTER );
    gridbag.setCons traints(top3, c);
    p2.add(top3);

    c.gridwidth = GridBagConstrai nts.REMAINDER;
    Label top4 = new Label("About");
    top4.setAlignme nt(Label.CENTER );
    gridbag.setCons traints(top4, c);
    p2.add(top4);

    // On next line, create the textarea
    TextArea comments = new TextArea(3, 50);
    comments.setEdi table(true);
    comments.setTex t("Comments:" );
    gridbag.setCons traints(comment s, c);
    p2.add(comments );

    }
Working...