Article View: borland.public.jbuilder.java.swing
Article #10610GridBagLayout Help Please!
From: Kenneth Sloane
Date: Tue, 31 Aug 1999 00:00
Date: Tue, 31 Aug 1999 00:00
51 lines
2625 bytes
2625 bytes
I'm trying to write code for a dialog box with the GridBagLayout manager.
I'm having trouble with the distribution of the two radio buttons and the
list below. I'm not sure what I'm doing wrong. The two radio buttons
appear at the top of the screen and then there is a large gap between the
radio buttons and the list box. I can't seem to figure out why. Can anyone
help?
void jbInit(Frame frame) throws Exception {
JPanel contentPane = new JPanel();
GridBagLayout gridBag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
Vector listItems = new Vector();
c.fill = GridBagConstraints.HORIZONTAL;
this.setSize(frame.getSize().width * 1/2, frame.getSize().height * 2/5);
this.setLocation((int)(frame.getLocation().getX() +
((frame.getSize().width - this.getSize().width) / 2)),
(int)(frame.getLocation().getY() + ((frame.getSize().height -
this.getSize().height) / 2)));
contentPane.setLayout(gridBag);
this.setContentPane(contentPane);
JRadioButton newStoryButton = new JRadioButton("New Story");
c.gridx = 1;
c.gridy = 0;
c.anchor = GridBagConstraints.NORTH;
c.insets = new Insets(0,50,0,0);
gridBag.setConstraints(newStoryButton, c);
contentPane.add(newStoryButton);
JRadioButton existingStoryButton = new JRadioButton("Exitsing Story");
c.gridx = 1;
c.gridy = 1;gridBag.setConstraints(existingStoryButton, c);
contentPane.add(existingStoryButton");
ButtonGroup group = new ButtonGroup();
group.add(newStoryButton);
group.add(existingStoryButton);
newStoryButton.setSelected(true);
listItems.addElement("More Files");
JList list = new JList(listItems);
c.gridx = 0;
c.weightx=0.1;
c.weighty=0.1;
c.gridy = 2;
c.gridwidth = frame.getSize().width * 1/2;
c.anchor = GridBagConstraints.WEST;
c.insets = new Insets(0, 0, 0, 0);
gridBag.setConstraints(list, c);
contentPane.add(list);
this.setVisible(true);
}
}
Technical Details
Message-ID:
<7qi24h$d04$2@nntp5.atl.mindspring.net>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,2c344da256d6b951,start X-Google-Attributes: gid111d45,public From: "Kenneth Sloane" <ksloane31@mindspring.com> Subject: GridBagLayout Help Please! Date: 1999/08/31 Message-ID: <7qi24h$d04$2@nntp5.atl.mindspring.net> X-Deja-AN: 519650659 X-Priority: 3 X-Server-Date: 1 Sep 1999 02:13:37 GMT X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 Organization: MindSpring Enterprises X-MSMail-Priority: Normal Reply-To: "Kenneth Sloane" <ksloane31@mindspring.com> Newsgroups: borland.public.jbuilder.java.swing