Article View: borland.public.jbuilder.java.swing
Article #7634Re: How do you REALLY set column widths in a table?
From: Torsten Welches
Date: Wed, 10 Jan 2001 12:11
Date: Wed, 10 Jan 2001 12:11
44 lines
2320 bytes
2320 bytes
Steve,
the snippet is fine.
My bet is a missing "import javax.swing.table.*;" ;-)
If not please post your surrounding code.
If you don't explicitly set a model JTable provides a
DefaultTableModel for you.
Please note that the snippet assumes 5 columns, if you have only two columns you would have to use "i < 2". Or just write
table.getColumnModel().getColumn(0).setPreferredWidth(100);
table.getColumnModel().getColumn(1)).setPreferredWidth(50);
Good luck,
Torsten
"Steve Swett" <swett@ncats.net> wrote:
>The following code at the "How to Use Tables" section of the on-line Java
>Tutorial doesn't work for me:
>
>TableColumn column = null;
>for (int i = 0; i < 5; i++) {
> column = table.getColumnModel().getColumn(i);
> if (i == 2) {
> column.setPreferredWidth(100); //sport column is bigger
> } else {
> column.setPreferredWidth(50);
> }
>}
>
>It won't even compile because it complains about the
>"column.setPreferredWidth(100)" statement as if it was a bad method. If you
>let Jbuilder prompt for you, after you key "column." it won't list the
>setPreferredWidth method.
>
>My table is a simple one and doesn't use a model. Does it need to?
>
>Can someone give me a simple example of setting column widths for a 2-column
>table where the first column is twice the width of the second column?
>Thanks.
>
>
>
Technical Details
Message-ID:
<3a5c5186_1@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.gamma.ru!Gamma.RU!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!dnews!207.105.83.65References:
<3a5c3183_2@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,72d904887cb9b6b9 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2001-01-10 04:16:10 PST From: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Sender: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Reply-To: "Torsten Welches" <torsten.welches@who.cares.netcologne.de> Subject: Re: How do you REALLY set column widths in a table? Newsgroups: borland.public.jbuilder.java.swing X-User-Info: 193.158.55.74 193.158.55.74 References: <3a5c3183_2@dnews> NNTP-Posting-Host: 207.105.83.65 Message-ID: <3a5c5186_1@dnews> Date: 10 Jan 2001 04:11:50 -0800 X-Trace: 10 Jan 2001 04:11:50 -0800, 207.105.83.65 Lines: 45 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!newsfeed.gamma.ru!Gamma.RU!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!bornews.borland.com!dnews!207.105.83.65