Search code examples
javaswingjtablejtableheadertext-size

How do I get a JTable header to display entire column names instead of shortening them?


I've a JTable that I fill with a class that extends AbstractTableModel. The problem is that the columns are too short to display the column name. I've turned off Jtable AutoResizeMode property, but shortening still occurs. How do I solve this?


Solution

  • Setting off autoresizemode only prevent the JTable's coumns to be resized. To force a particular width retrieve the table column model:

    TableColumn column = jtable.getColumnModel().getColumn(col_num);
    

    and set the desired width:

    column.setPreferredWidth(width);