Why does my JTable sort an integer column incorrectly?

后端 未结 4 926
情深已故
情深已故 2020-12-01 21:02

I have a JTable that uses a DefaultTableModel and I allow for sorting when the user clicks on the column headers. However, when the user clicks on a header for a column that

4条回答
  •  春和景丽
    2020-12-01 21:53

    Here is the answer: Problems with JTable sorting of integer values

    The idea is to define classes for columns.

    myTable.setModel(new DefaultTableModel(Object[][] tableData, String[] columnsNames){
        Class[] types = { Boolean.class, Boolean.class, String.class, String.class };
    
        @Override
        public Class getColumnClass(int columnIndex) {
            return this.types[columnIndex];
        }
    });
    

提交回复
热议问题