我在 Netbeans 中创建了 jtable。
tableMalzeme.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false, false
};
public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
我想按数字排序。 “getColumnClass”的默认值为“Object”,但我想更改此值。 你是怎么做到的?
tableMalzeme.setModel(DbUtils.resultSetToTableModel(resultSet));
tableMalzeme.setAutoCreateRowSorter(true);
tableMalzeme.getColumnClass(0).cast(Integer.class);
最佳答案
sorted as a String but I want to sort as a Integer
您需要:
- 将
Integer
对象添加到TableModel
- 重写
getColumnClass(...)
类方法以返回包含整数的列的Intgeger.class
。
关于java - Jtable 整数值排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24437340/