🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #75

Re: GridBagLayout

#75
From: Infernoz
Date: Thu, 22 Dec 2005 13:13
50 lines
3054 bytes
I suggest you use packer, a GridBagLayout helper, it is much easier to 
use that GridBagLayout on it's own, see:
https://packer.dev.java.net/

BTW: There is some odd behaviour (IMHO bugs) in GridBagLayout, which I 
found using packer, so it is worth trying extra constraints, even if 
they don't make sense.  BoxLayout maybe useful if you get stuck and 
don't have time to experiment.


Hiroshi 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: <43aaa627$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <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
Date: Thu, 22 Dec 2005 13:13:46 +0000
From: Infernoz <auto102767@hushmail.com>
User-Agent: Thunderbird 1.5 (Windows/20051201)
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing
Subject: Re: GridBagLayout
References: <43925b0a$1@newsgroups.borland.com>
In-Reply-To: <43925b0a$1@newsgroups.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 81.86.166.110
Message-ID: <43aaa627$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1135257127 81.86.166.110 (22 Dec 2005 05:12:07 -0700)
Lines: 50
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!news-out.newsfeeds.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail