我的jtable无法正确排序我的整数

时间:2019-11-23 16:58:08

标签: java sorting jtable

当我单击列顶部以对数字进行排序时,它们无法正确排序。例: -89 -50 -100 当我对这些数字进行排序时,它们会变成: -100 -50 -89

显示表并对其进行排序的代码是:

public void showTable() {
        String matrix[][] = new String[list.size()][5];

        for (int i = 0; i < list.size(); i++) {
            matrix[i][0] = list.get(i).getCodigo();
            matrix[i][1] = list.get(i).getNombre();
            matrix[i][2] = list.get(i).getCarrera();
            matrix[i][3] = list.get(i).getSemestre();
            matrix[i][4] = list.get(i).getPromedio();
        }

        jtStudents.setModel(new javax.swing.table.DefaultTableModel(matrix, new String [] {"Codigo", "Nombre", "Carrera", "Semestre", "Promedio"}));

        tm = new DefaultTableModel(matrix, new String [] {"Codigo", "Nombre", "Carrera", "Semestre", "Promedio"}){
            public Class getColumnClass(int column) {
                Class Value;
                if (column >= 0 && column < getColumnCount()) {
                    Value = getValueAt(0, column).getClass();
                } else {
                    Value = Object.class;
                }
                return Value;
            }
        };


        jtStudents.setModel(tm);
        tableSorted = new TableRowSorter<>(jtStudents.getModel());
        jtStudents.setRowSorter(tableSorted);
    }

0 个答案:

没有答案