user3399540
user3399540

Reputation: 3

Jtable sorting of integer values

I created jtable in Netbeans.

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];
}
});

I want to sort numerically. Default value of "getColumnClass" is "Object" but I want to change this value. How do you make it?

 tableMalzeme.setModel(DbUtils.resultSetToTableModel(resultSet));               
 tableMalzeme.setAutoCreateRowSorter(true);
 tableMalzeme.getColumnClass(0).cast(Integer.class);

Upvotes: 0

Views: 730

Answers (2)

Thimershen
Thimershen

Reputation: 7

Try this code( hope this is what you are looking for):

(Integer)(tableMalzeme.getColumnClass(0));

Upvotes: 0

camickr
camickr

Reputation: 324108

sorted as a String but I want to sort as a Integer

You need to:

  1. Add Integer objects to the TableModel
  2. Override the getColumnClass(...) class method to return Intgeger.class for the column that contains integers.

Upvotes: 2

Related Questions