title: JTable sorter not working
body: <p>I have a very simple JTable that I want to sort in ascending order by column 0. The code is very simple. But it is not able to sort the rows properly. I can not figure out what is wrong. Following is my code:</p>
  
  <pre><code>package test;
  
  import java.util.List;
  import javax.swing.JFrame;
  import javax.swing.JScrollPane;
  import javax.swing.JTable;
  import javax.swing.RowSorter;
  import javax.swing.SortOrder;
  import javax.swing.UIManager;
  import javax.swing.UnsupportedLookAndFeelException;
  import javax.swing.table.DefaultTableModel;
  import javax.swing.table.TableModel;
  import javax.swing.table.TableRowSorter;
  
  public class TableSorter {
  
      public static void main(String[] args) {
          new TableSorter();
      }
  
      public TableSorter() {
          EventQueue.invokeLater(new Runnable() {
              @Override
              public void run() {
                try {
  
  
         UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                 } catch (ClassNotFoundException | InstantiationException | 
         IllegalAccessException | UnsupportedLookAndFeelException ex) {
                      ex.printStackTrace();
                  }
  
  
              DefaultTableModel model =  new DefaultTableModel(new String[] {"X", "Y", }, 0);
  
              model.addRow(new Object[]{5, 8});
              model.addRow(new Object[]{10, 5});
              model.addRow(new Object[]{50, 60});
              model.addRow(new Object[]{100, 60});
  
              JTable table = new JTable(model);
              TableRowSorter&lt;TableModel&gt; sorter = new TableRowSorter&lt;TableModel&gt;(table.getModel());
              table.setRowSorter(sorter);
  
  
              List&lt;RowSorter.SortKey&gt; sortKeys = new ArrayList&lt;&gt;();
              sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
              sorter.setSortKeys(sortKeys);
  
              JFrame frame = new JFrame("Testing");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.add(new JScrollPane(table));
              frame.pack();
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
              }
          });
      }
  
     }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/aYdM9.png" rel="nofollow noreferrer">Here is the result when I run the program</a></p>
  
  <p>Results:</p>
  
  <pre><code>X    y
  10   5
  100  60
  5    8
  50   60
  </code></pre>
  
  <p>Any help will be appreciated. The result is attached. 
  Thanks in advance.</p>