0
public projectframe() {
    initComponents();
    jTable2.setAutoCreateRowSorter(true);
}

I want to sort my data I used that code for sorting but sometimes in the Integer error.

like that I can't sort with true screenshot

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    It looks like `getValueAt` returns `String` instead of `Integer` – ThomasEdwin Jan 03 '18 at 05:05
  • can you show more code? – johnII Jan 03 '18 at 05:21
  • Can you check whether value set in the table for Quantity and Price is Integer? – Gnanasekaran Palanisamy Jan 03 '18 at 05:30
  • DefaultTableModel model = (DefaultTableModel) jTable2.getModel(); name.setText(jTable2.getValueAt(jTable2.getSelectedRow(), 0).toString()); quantity.setText(jTable2.getValueAt(jTable2.getSelectedRow(), 1).toString()); price.setText(jTable2.getValueAt(jTable2.getSelectedRow(), 2).toString()); – osel dharma Jan 03 '18 at 05:42
  • 1
    Java is performing a "natural" sort on the strings, which is based on the textual or ascii based values, not the numerical values. You need to store physical `int` values in the columns so they are sorted using their numerical values instead – MadProgrammer Jan 03 '18 at 06:42
  • 1
    [For example](https://stackoverflow.com/questions/6592192/why-does-my-jtable-sort-an-integer-column-incorrectly) and [for an explanation](https://softwareengineering.stackexchange.com/questions/127639/why-do-some-sorting-methods-sort-by-1-10-2-3) – MadProgrammer Jan 03 '18 at 06:43

0 Answers0