title: JTable duplicate entry
body: <p>How can I prevent duplication of data in JTable?
  The for loop determines whether the data contains similar ID.
  Yes, it determines and show a JOptionPane which works.
  But my problem is that it scans for a duplicate after I setValue on table 2.
  I want my program to prevent duplication of data before it setValue on table 2.</p>
  
  <pre><code>public void dProductList(){
      table.addMouseListener(new MouseAdapter(){
          public void mouseClicked(MouseEvent e) {
              if(e.getClickCount() == 1) {
                  JTable tbl = (JTable)e.getSource();
                  int rrow = tbl.getSelectedRow();
                  if(rrow&gt;=0) {
                      int dcol = 0;
                      int rcol = 0;
                      ((DefaultTableModel)table2.getModel()).addRow(new Object[] {0,0,0,0});
  
                      while(rcol&lt;table2.getColumnCount()-1) {
  
                                  table2.setValueAt(table.getValueAt(rrow,rcol),drow,dcol);
                                  totalAmount = totalAmount + (int) table2.getValueAt(drow,3);
                                  rcol++;
                                  dcol++;
                                  if(rcol==table2.getColumnCount()-1) {
                                  drow++;
                                  }
                                  label.setText(String.valueOf(totalAmount));         
  
                      }
                      for(int i=0; i&lt;table2.getRowCount()-1;i++){     
                          if(table2.getValueAt(i,0).equals(table2.getValueAt(table2.getRowCount()-1,0))){
  
                              JOptionPane.showMessageDialog(null,"item already listed");
                          }       
                      }
  
  
                          }
  
  
                  }
          }
      });
  }
  </code></pre>