[Advanced-java] Horizontally Scroll in JTable
(WrappedbyJScrollPane)
Daniel Jutzi
daniel.jutzi at it-vision.com
Wed Apr 2 16:00:38 2003
You have to calc the max width of each cell and then set this size to
the column.
Cheers
Dan
Alvin Wang wrote:
>Thanks for all the replies. However, is there a way we can let JTable decide
>the width it needs to fully display the data for each column? I do not want
>to hardcode the column width since it is hard to predict the data that will
>be displayed.
>
>Thanks!
>
>
>
>
>>-----Original Message-----
>>From: advanced-java-bounces@lists.xcf.berkeley.edu
>>[mailto:advanced-java-bounces@lists.xcf.berkeley.edu]On Behalf Of
>>Michiel Westland
>>Sent: Wednesday, April 02, 2003 2:02 AM
>>To: advanced-java@lists.xcf.berkeley.edu
>>Subject: RE: [Advanced-java] Horizontally Scroll in JTable
>>(WrappedbyJScrollPane)
>>
>>
>>Dear Alvin,
>>
>>
>>For example, use:
>> table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
>>
>>to set autoresize off and
>> table.getColumnModel().getColumn(2).setPreferredWidth(50);
>>
>>to set the width of the third colummn (index 2) to 50 pixels.
>>
>>
>>Michiel Westland
>>
>>
>>-----Oorspronkelijk bericht-----
>>Van: advanced-java-bounces@lists.xcf.berkeley.edu
>>[mailto:advanced-java-bounces@lists.xcf.berkeley.edu]Namens Alvin Wang
>>Verzonden: dinsdag 1 april 2003 21:39
>>Aan: advanced-java@lists.xcf.berkeley.edu
>>Onderwerp: [Advanced-java] Horizontally Scroll in JTable (Wrapped
>>byJScrollPane)
>>
>>
>>Hi! I am writing a JTable with a lot of columns. Java will try to
>>shrink the
>>columns to display all of them. So some data will be displayed as
>>"-12...".
>>The user has to widen the column manually to see the data. It is not
>>convenient. My JTable is wrapped by a JScrollPane, so I wanto let JTable
>>just use whatever width it needs for each column to display the data, and
>>the user can scroll horizontally. Can any gurus tell me how to do it? I
>>think the main problem is how to disallow JTable from shrinking.
>>
>>Thanks!
>>
>>_______________________________________________
>>Advanced-java mailing list
>>Advanced-java@lists.xcf.berkeley.edu
>>http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
>>
>>_______________________________________________
>>Advanced-java mailing list
>>Advanced-java@lists.xcf.berkeley.edu
>>http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
>>
>>
>
>_______________________________________________
>Advanced-java mailing list
>Advanced-java@lists.xcf.berkeley.edu
>http://lists.xcf.berkeley.edu/mailman/listinfo/advanced-java
>
>