Help with column resizing

Hi,

Relatively new to java swing...

I have a JTable inside a JScrollPane that gets filled dynamically. What I would like to happen is to set a min column width, and then have each column be large enough to fit its largest cell (by largest cell I mean the cell in the column that has the most data to display). If this is too large for the pane, a scrollbar should come up. Right now I am using

setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

but the column sizes are showing up only as big as the column headers need to be, and then for the other cells in the column i getsome of my data followed by "..." It lets me manually resize the columns so that everything looks OK, but I would rather have it start out this way

Thanks for any tips...

[784 byte] By [Mark13a] at [2007-11-27 2:24:49]
# 1

> but the column sizes are showing up only as big as the column headers need to be,

The size of the header has nothing to do with the size of the column. The column width defaults to 75 pixels. If you want to change the size then you need to manually calculate the width of the column.

Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/table.html#width]Setting Column Widths[/url]. Then check out [url http://www.exampledepot.com/egs/javax.swing.table/PackCol.html]Packing a Column[/url].

camickra at 2007-7-12 2:32:21 > top of Java-index,Desktop,Core GUI APIs...
# 2
Yeah, it was just a coincidence that my headers were about that size. Thanks for the links, though
Mark13a at 2007-7-12 2:32:21 > top of Java-index,Desktop,Core GUI APIs...