title: JTable Sorting - Selecting a row
body: <p>I have a JTable where I used an integer comparator along with a <code>TableRowSorter</code>
  <code>trs.setComparator(columnIndex, new IntComparator())</code> and <code>table.setRowSorter(trs)</code> to sort. </p>
  
  <p>The sorting works as intended however I have a mouse clicked event which uses <code>int row = table.rowAtPoint(e.getPoint())</code> and <code>DefaultTabelModel mod = (DefaultTableModel)table.getModel()</code> to get the values of the row selected with <code>mod.getValueAt(row, 0)</code>. </p>
  
  <p>This gets the value of the row at this position in the original sorting of the JTable, not the row that is there now after sorting. How can I make this work for the sorted table as well?</p>
  
  <p>Thanks</p>
  
  <p>EDIT: Example code</p>
  
  <pre><code>import javax.swing.*;
  import javax.swing.table.DefaultTableModel;
  import javax.swing.table.TableRowSorter;
  import java.awt.*;
  import java.awt.event.MouseAdapter;
  import java.awt.event.MouseEvent;
  import java.util.Comparator;
  
  public class Test extends JFrame{
      JTable table = new JTable();
      JPanel panel = new JPanel();
  
      public Test() {
          add(panel);
          pack();
          setResizable(false);
          setVisible(true);
          setSize(1280, 720);
          setupTable();
      }
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
                  new Test();
              }
          });
      }
      public void setupTable() {
  
          Object[][] data = new Object[][]{
                  {1, 15, 17},
                  {2, 45, 7},
                  {3, 9, 26},
                  {4, 65, 65}
          };
          Object[] columns = new Object[]{"ID", "X", "Y"};
  
          table = new JTable(new DefaultTableModel(data, columns) {
              @Override
              public boolean isCellEditable(int row, int column) {
                  return false;
              }
          });
  
          table.setPreferredScrollableViewportSize(new Dimension(720, 400));
          table.setFillsViewportHeight(true);
          JScrollPane scrollPane = new JScrollPane(table);
          panel.add(scrollPane);
          TableRowSorter&lt;DefaultTableModel&gt; trs = new TableRowSorter(table.getModel());
  
  
          class IntComparator implements Comparator {
              public int compare(Object o1, Object o2) {
                  Integer int1 = (Integer) o1;
                  Integer int2 = (Integer) o2;
                  return int1.compareTo(int2);
              }
  
              public boolean equals(Object o2) {
                  return this.equals(o2);
              }
          }
          for (int i = 0; i &lt; 3; i++) {
              trs.setComparator(i, new IntComparator());
          }
          table.setRowSorter(trs);
          table.setAutoCreateRowSorter(false);
  
          table.addMouseListener(new MouseAdapter() {
              @Override
              public void mouseClicked(MouseEvent e) {
                  int row = table.rowAtPoint(e.getPoint());
                  if (0 &lt;= row &amp;&amp; row &lt;= table.getRowCount()) {
                      DefaultTableModel mod = (DefaultTableModel) table.getModel();
                      String ID = String.valueOf(mod.getValueAt(trs.convertRowIndexToView(row), 0));
                      System.out.println(ID);
                  }
              }
          });
      }
  }
  </code></pre>