🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: How do you REALLY set column widths in a table?

#7635
From: Torsten Welches
Date: Wed, 10 Jan 2001 12:13
50 lines
2568 bytes
make that 
  table.getColumnModel().getColumn(1).setPreferredWidth(50);

"Torsten Welches" <torsten.welches@who.cares.netcologne.de> wrote:
>
>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: <3a5c51f3$1_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!fr.clara.net!heighliner.fr.clara.net!news.imp.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!dnews!207.105.83.65
References: <3a5c3183_2@dnews> <3a5c5186_1@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:22: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>   <3a5c5186_1@dnews> 
NNTP-Posting-Host: 207.105.83.65
Message-ID: <3a5c51f3$1_1@dnews>
Date: 10 Jan 2001 04:13:39 -0800
X-Trace: 10 Jan 2001 04:13:39 -0800, 207.105.83.65
Lines: 51
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!news-out.usenetserver.com!fr.clara.net!heighliner.fr.clara.net!news.imp.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!dnews!207.105.83.65