JTables...

hi,Having a 'problem; with my JTable in that i want it to auto resize the columns to fit the longest text string on that column.can anyone offer any help to doing this?Thanks.Cav.
[215 byte] By [Cav123a] at [2007-10-2 9:50:24]
# 1

How about setting the width of the column in your cell renderer

i.e.

public Component getTableCellRendererComponent(

JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column )

{

TableColumn col = table.getColumnModel().getColumn(column);

// if the preferred size of the renderer is > col.getWidth

if (renderer.getPreferredSize().width > col.getWidth() ) {

col.setPreferredWidth(renderer.getPreferredSize().width;

}

}

mpmarronea at 2007-7-16 23:55:34 > top of Java-index,Desktop,Core GUI APIs...