title: Get value from a cell in JTable
body: <p>I've looked everywhere but can't seem to figure this out. I just want to pull out a cell's value from my JTable when a user clicks on it.</p>
  
  <p>However at the moment I am getting -1 so I suppose double clicking results in no row being detected. Here is the code:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import java.sql.SQLException;
  import javax.swing.*;
  import javax.swing.table.TableColumn;
  
  public class CardLayoutExample {
      private static JScrollPane scrollPane;
  
    public static void main(String[] arguments) throws SQLException {
  
      // main window
      JFrame.setDefaultLookAndFeelDecorated(true);
      JFrame window = new JFrame("CardLayout Example");
      window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      window.setSize(1500,800); 
      window.getContentPane().setLayout(new BorderLayout());
  
  
  
  final CardLayout cardLayout = new CardLayout(); 
  final JPanel cardPanel = new JPanel(cardLayout);
  
  JPanel card3 = new JPanel();
  cardPanel.add(card3,"All Patients");
  
  String AllPatients="select * from tblPtDetails";
      JTable tablePatientDt = new   JTable(Bquery.buildTableModel(Bquery.resultQuery(AllPatients)));
      tablePatientDt.setEnabled(false);
      tablePatientDt.setPreferredScrollableViewportSize(new Dimension(1200, 400));
      tablePatientDt.setAutoResizeMode( JTable.AUTO_RESIZE_OFF ); 
      tablePatientDt.setRowHeight(30);
      tablePatientDt.setAutoCreateRowSorter(true);
      card3.add(tablePatientDt);
      card3.add(new JScrollPane(tablePatientDt), BorderLayout.CENTER);
      for (int i = 0; i &lt; (tablePatientDt.getColumnCount()); i++) {
          TableColumn columnPatients = null;
          columnPatients = tablePatientDt.getColumnModel().getColumn(i);
          columnPatients.setPreferredWidth(70); //sport column is bigger
  
      }
      tablePatientDt.addMouseListener(new MouseAdapter() {
             public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                   int row = tablePatientDt.getSelectedRow();
                   int column = tablePatientDt.getSelectedColumn();
                   //Object val= tablePatientDt.getModel().getValueAt(row, column);
                   //tablePatientDt.getModel().getValueAt(row, column);
                   //return tablePatientDt.getModel().getValueAt(row, column);
                   System.out.println(row);
                   JFrame newFrame = new JFrame();
                   newFrame.setTitle("Detail Screen");
                   newFrame.setVisible(true);
                   }
             }
          });
  </code></pre>