If I understand Your problem correctly then Your JTable size is too large.

The inital sizing of JTable is something strange.

You can try out the following:

        TableColumnModel columnModel = table.getColumnModel();
        columnModel.getColumn(0).setPreferredSize(20);
        columnModel.getColumn(1).setPreferredSize(20);

        Dimension preferredViewportSize = new Dimension(20 + 20, 50);
      table.setPreferredScrollableViewportSize( preferredViewportSize);

        
You should then receive a table of size 40 x 50 pixels, if Your table
component is contained
in a scrollpane.

Regards

Urs


-----Original Message-----
From: Bill Tschumy [mailto:[EMAIL PROTECTED]]
Sent: Mittwoch, 25. April 2001 15:32
To: Christian Pesch
Cc: [EMAIL PROTECTED]
Subject: Re: Help with JTable column width


No, that doesn't help but thanks for the suggestion.  I have found a 
partial solution, but I don't know why my original method fails.

When I would change the host status I need to update the icon in 
column 0.  To do so I used the following code.

     public void statusChanged(RemoteHost host)
     {
         tableModel.fireTableRowsUpdated(hosts.indexOf(host), 
hosts.indexOf(host));
     }

The call to fireTableRowsUpdated() is what messes up the column 
widths.  If I change this to a simple repaint() on the JTable the new 
status is correctly displayed.  Of course, listeners are not 
notified, but I can handle that in other ways.

Isn't it the case that I should call fireTableRowsUpdated() when I 
know the TableModel has new data to display?



At 9:06 AM +0000 4/25/01, Christian Pesch wrote:
>Bill Tschumy schrieb:
>
>>  Why is the table allocating so much space to the column?
>
>How about trying to set the second column to be resizable?
>
>>           column = getColumnModel().getColumn(0);
>>           column.setPreferredWidth(20);
>>           column.setMinWidth(20);
>>           column.setMaxWidth(20);
>>           column.setResizable(false);
>>
>>           column = getColumnModel().getColumn(1);
>>           column.setResizable(false);
>
>Set this to true. This might solve your resize problems,
>since for now the JTable has the problem, that according
>to the ColumnModel it is not allowed to resize but the container
>of the JTable donates it more spaces. Thus the JTable streches
>the columns on its own.
>
>--
>Christian Pesch - Software Engineer
>[EMAIL PROTECTED] - fon +49.40.325587.505  fax .999
>CoreMedia AG - www.coremedia.com - 0700-COREMEDIA
>Erste Brunnenstraße 1, 20459 Hamburg, Germany
>
>CoreMedia - Think ahead! We're there.

-- 
Bill Tschumy
Otherwise -- Austin, TX
[EMAIL PROTECTED]
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to