Align the values of the cells in JTable?

后端 未结 7 839
闹比i
闹比i 2020-12-18 18:28

I\'m not aware of how to align the values of cells in JTable.

For Ex,The Jtable shows, Name Salary Mr.X 100000.50 XXXX 234.34

7条回答
  •  清酒与你
    2020-12-18 19:03

    A simple way is using DefaultTableModel and override method getColumnClass()
    Ex:

    DefaultTableModel model = new DefaultTableModel() {
            @Override
            public Class getColumnClass(int columnIndex) {
                if (columnIndex == 0) {
                    return Integer.class;
                } else {
                    return String.class;
                }
            }
        };
    

    If you return Integer, your column will align right anh if return String your column will align left.

提交回复
热议问题