Article View: borland.public.jbuilder.java.swing
Article #76Re: GridBagLayout
From: Hiroshi
Date: Fri, 23 Dec 2005 10:49
Date: Fri, 23 Dec 2005 10:49
59 lines
3601 bytes
3601 bytes
Thank you very much for your response. Yes, I'd like to try it out sometime.
I gave up GridBagLayout (since I didn't receive any response and since I didn't find anything on the Internet relating to my problem), and am using BoxLayout now as you suggested. Its behaviour is much predictable and logical; using struts and the nested Boxes, we can do what GrigBagLayout premisses, although code becomes longer and messy...)
Thanks again.
Infernoz <auto102767@hushmail.com> wrote:
>
>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:
<43abe462$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!newsfeed.freenet.de!newsfeed.inode.at!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<43925b0a$1@newsgroups.borland.com> <43aaa627$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> <43aaa627$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <43abe462$1@newsgroups.borland.com> Date: 23 Dec 2005 03:49:54 -0700 X-Trace: newsgroups.borland.com 1135338594 207.105.83.66 (23 Dec 2005 03:49:54 -0700) Lines: 60 Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!news-xfer.newsread.com!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!newsfeed.freenet.de!newsfeed.inode.at!news-out.newsgroups.com!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail