title: How to get the value of the selected row in Jtable
body: <p>I have this code</p>
  
  <pre><code>     ArrayList&lt;User&gt; list = bookList();
       dm=(DefaultTableModel) table2.getModel(); 
       Object[] row= new Object[3];
      for(int i=0;i&lt;list.size(); i++){
      row[0]=list.get(i).getbooks();
      row[1]=list.get(i).getstrandSection();
      row[2]=list.get(i).getprice();
      dm.addRow(row);
      JOptionPane.showMessageDialog(null, "Added to cart");
  </code></pre>
  
  <p>but the problem is when i click the button it add all the items to cart</p>