Montag, 5. November 2007

How to set the column width of a JTable?

If you want your JTable to display a fixed columnwidth which the user cannot change, you have to set the minWidth and the maxWidth of a column.

To set all columns to a fixed width of 10, use this code or modify it to your needs.



for (int i = 0; i < table.getColumnCount(); i++){ table.getColumn(table.getColumnName(i)).setMaxWidth(10); table.getColumn(table.getColumnName(i)).setMinWidth(10);
}

Keine Kommentare: