Auto resizing the JTable column widths

后端 未结 4 878
伪装坚强ぢ
伪装坚强ぢ 2020-11-27 05:13

I need my JTable to automatically re-size its column widths to fit the content. I found the TableColumnAdjuster class very useful. But there\'s a small problem. Say i have 5

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 06:05

    setAutoResizeMode() will tell your table how to resize you should give it a try will all different options available to see the differences, in My case I wanted to specifically resize two columns and let it decide how to adjust all the other ones.

    jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN);
    TableColumnModel colModel=jTable1.getColumnModel();
    colModel.getColumn(1).setPreferredWidth(25);    
    colModel.getColumn(2).setPreferredWidth(400);
    

提交回复
热议问题