Article View: borland.public.jbuilder.java.swing
Article #63Re: GridBagLayout
From: Hiroshi
Date: Thu, 08 Dec 2005 08:49
Date: Thu, 08 Dec 2005 08:49
66 lines
3586 bytes
3586 bytes
I spent quite some time in visiting Sun MicroSystems web site.
One of their documents: http://jave.sun.com/developer/
technicalArticles/GUI/AWTLayoutMgr/index.htm says something
relating to my issue.
"When you specify a component as the last or next-to-last
component in a row, you can give it a gridheight value greater
than one as the component spans multiple rows. However, in this
case, there is no way to make the component wider than one
column when it is the last or next-to-last component in the
row." Also it says
"Due to a GridBagLayout bug, you can use gridheight to have a
component span multiple rows only if the component is in Column
0 or if gridx and gridy have positive values."
If above statements are true even today, the layout has a
serious limitation/drawback I must say.
I wonder why such a limitation is needed...
My issue must be quite common because my layout is nothing
unusual, thus, lots of people must have experienced...
Please respond if you have any idea about my issue.
"Hiroshi" <hiroshinakata@hotmail.com> wrote:
>
>Hi everyone, I am planning to post a dialog of 10 JPanels
>using the layout, but I cannot make them aligned as I want.
>Below is the code to illustrate the problem - some cells get
>2 cols while asking 1, and other gets 1 cell while asking 2.
>
>JPanel pnls[]={
> new JPanel(),new JPanel(),new JPanel(),new JPanel(),
> new JPanel(),new JPanel(),new JPanel(),new JPanel(),
> new JPanel(),new JPanel()};
>JLabel lbls[]={//digits ~ gridx,gridy,gridwidth,and gridheight
> new JLabel("0011"),new JLabel("1021"),new JLabel("3011"),
> new JLabel("0111"),new JLabel("1113"),new JLabel("2121"),
> new JLabel("0211"),new JLabel("2222"),new JLabel("0311"),
> new JLabel("0441")};
>for (i=0;i<10;i++) pnls[i].add(lbls[i]);
>int gx[]={0,1,3,0,1,2,0,2,0,0}, //gridx for i-th cell
> gy[]={0,0,0,1,1,1,2,2,3,4}, //gridy "
> gw[]={1,2,1,1,1,2,1,2,1,4}, //gridwidth "
> gh[]={1,1,1,1,3,1,1,2,1,1}; //gridheight "
>gbc.fill=GridBagConstraints.BOTH;
>for (i=0;i<10;i++) {
> pnls[i].add(lbls[i]); //(to make panels identifyable)
> gbc.gridx=gx[i]; gbc.gridy=gy[i]; //Set the position
> gbc.gridwidth=gw[i]; gbc.gridheight=gh[i]; //and the size
> gbl.setConstraints(pnls[i],gbc); //constraints for all cells.
> pnls[i].setBorder(BorderFactory.createEtchedBorder());
> dlgCp.add(pnls[i]);
>}
>super.setTitle("GridBagLayout Test");
>setBounds(10,10,200,200);
>show();
>
>As you can see, cell "1113" (~gridx=1;gridy=1;gridwidth=1;
>gridheight=3) gets 2 cols while asking 1, and cell "2121"
>and "2222" get 1 col while asking 2...
>
>Any idea? Thanks.
>
Technical Details
Message-ID:
<43980194$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43925b0a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 111d45,ec28a2fb91b52693 X-Google-Attributes: gid111d45,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Hiroshi" <hiroshinakata@hotmail.com> Sender: "Hiroshi" <hiroshinakata@hotmail.com> Reply-To: "Hiroshi" <hiroshinakata@hotmail.com> Subject: Re: GridBagLayout Newsgroups: borland.public.jbuilder.java.swing X-User-Info: 69.192.157.16 References: <43925b0a$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <43980194$1@newsgroups.borland.com> Date: 8 Dec 2005 01:49:08 -0700 X-Trace: newsgroups.borland.com 1134035348 207.105.83.66 (8 Dec 2005 01:49:08 -0700) Lines: 67 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!news-peer0-test!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail