Java JTable setting Column Width

后端 未结 9 1559
伪装坚强ぢ
伪装坚强ぢ 2020-12-02 09:57

I have a JTable in which I set the column size as follows:

table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
table.getColumnModel().getColumn(0).setPreferredW         


        
9条回答
  •  离开以前
    2020-12-02 10:43

    Use this code. It worked for me. I considered for 3 columns. Change the loop value for your code.

    TableColumn column = null;
    for (int i = 0; i < 3; i++) {
        column = table.getColumnModel().getColumn(i);
        if (i == 0) 
            column.setMaxWidth(10);
        if (i == 2)
            column.setMaxWidth(50);
    }
    

提交回复
热议问题