Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swing problem

Status
Not open for further replies.

fatcodeguy

Programmer
Feb 25, 2002
281
CA
Hi, I'm creating a small dialog using GridBagLayout. I have
one label, one text field and two buttons.. here's my code (they are set in a larger pane, and I want them at the top, that's why anchor north and yweights)

c.insets = new Insets(5,5,5,5);
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.NORTH;
c.gridx=0;
c.gridy=0;
c.weightx=0.0;
c.weighty=0.0;
c.gridwidth=1;
c.gridheight=1;
rightPanel.add(label,c);

c.fill=GridBagConstraints.BOTH;
c.gridx=1;
c.gridy=0;
c.weightx=0.0;
c.weighty=0.0;
c.gridwidth=2;
c.gridheight=1;
rightPanel.add(textField,c);

c.gridx=1;
c.gridy=1;
c.weightx=0.0;
c.weighty=-1;
c.gridwidth=1;
c.gridheight=1;
rightPanel.add(button1,c);

c.gridx=2;
c.gridy=1;
c.weightx=0.0;
c.weighty=-1;
c.gridwidth=1;
c.gridheight=1;
rightPanel.add(button2,c);

My problem is that I want the two buttons under the text field to be exactly the same size. How do I do this?
 
I would create another panel and give it a horizontal flow layout and add the two buttons to this new panel, then add the new panel to your parent panel as you were adding the buttons orginally.

Sometimes the best way of using SWing is to use a combination of several layouts for different elements of your GUI.

let me if this sorts you out.
 
Thanks pipk, great idea!! I used gridlayout instead, because the default is equal sized buttons, but the idea worked great!! thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top