3

when i click the 'Price' radiobutton it sorts the Price Row but in this order

  • 1
  • 11
  • 12
  • 13
  • 2
  • 21
  • 200
  • 3
  • 32
  • 300

how can i fix it? im still new in java. please help me. thanks. :D

rdbtnNewRadioButton_2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DefaultRowSorter sorter = ((DefaultRowSorter)table.getRowSorter());
            List <RowSorter.SortKey> sortKeys = new ArrayList<RowSorter.SortKey>();
            sortKeys.add(new RowSorter.SortKey(4, SortOrder.ASCENDING));
            sorter.setSortKeys(sortKeys); 

        }
    });
mKorbel
  • 109,525
  • 20
  • 134
  • 319
Rohan21
  • 353
  • 5
  • 9
  • 24

3 Answers3

4
  • override getColumnClass in your XxxTableModel, default class is String, the your result from RowSorter is correct

  • use Integer.Class

mKorbel
  • 109,525
  • 20
  • 134
  • 319
1

Write your own comparator and then

sorter.setComparator(int column, Comparator<?> comparator)

refer this Why does my JTable sort an integer column incorrectly?

Community
  • 1
  • 1
sadhu
  • 1,429
  • 8
  • 14
0

Convert your data column to an integer type in order to have the correct order.

SELECT
    ...,
    CAST(YourColumnName as INT) as YourColumnName
    ...
FROM...
bjnr
  • 3,353
  • 1
  • 18
  • 32