Article View: borland.public.jbuilder.java.swing
Article #10422Re: GridBagLayout Help Please!
From: Colin Mummery
Date: Sun, 26 Sep 1999 00:00
Date: Sun, 26 Sep 1999 00:00
73 lines
3286 bytes
3286 bytes
There's an online applet that I wrote for experimenting with
GridBagLayout's at
http://pages.hotbot.com/biz/equitysoft
It's actually a demo program for a standalone shareware version at
http://kagi.com/equitysoft.
It may be able to help you put together the layout you need.
In article <7qi24h$d04$2@nntp5.atl.mindspring.net>,
"Kenneth Sloane" <ksloane31@mindspring.com> wrote:
> 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);
> }
> }
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
Technical Details
Message-ID:
<7sm5cm$6r3$1@nnrp1.deja.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7qi24h$d04$2@nntp5.atl.mindspring.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,2c344da256d6b951 X-Google-Attributes: gid111d45,public From: Colin Mummery <equitysoft@my-deja.com> Subject: Re: GridBagLayout Help Please! Date: 1999/09/26 Message-ID: <7sm5cm$6r3$1@nnrp1.deja.com> X-Deja-AN: 529674037 References: <7qi24h$d04$2@nntp5.atl.mindspring.net> X-Http-Proxy: 1.1 x23.deja.com:80 (Squid/1.1.22) for client 195.115.200.194 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Sun Sep 26 22:06:20 1999 GMT X-MyDeja-Info: XMYDJUIDequitysoft Newsgroups: borland.public.jbuilder.java.swing X-Http-User-Agent: Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; CallNet PLC_w9x)