title: Prevent duplicate entries in JTable
body: <p>How to prevent duplicate entries in <code>JTable</code>?</p>
  
  <p>I want to stop enter duplicate data in table. I tried given below cord. But it is not working. My first column name is <code>item id</code>. So I used <code>jtable.getValueAt(i, 1)</code>. It that wrong. </p>
  
  <pre><code>public void lordTable(JTable jtable, JTextField txtItemID, JTextField txtName, JTextField txtQty, JTextField txtUp) {
      String s = "";
      boolean exists = false;
      for (int i = 0; i &lt; jtable.getRowCount(); i++) {
          s = jtable.getValueAt(i, 1).toString().trim();
  
          if (txtItemID.getText().equals("")) {
              JOptionPane.showMessageDialog(null, "Enter Invoice Details First");
          } else {
              if (txtItemID.getText().equals(s)) {
                  exists = true;
                  break;
              }
          }
      }
      if (!exists) {
          DefaultTableModel dd = (DefaultTableModel) jtable.getModel();
          Vector v = new Vector();
          v.add(txtItemID.getText());
          v.add(txtName.getText());
          v.add(txtQty.getText());
          v.add(txtUp.getText());
          Double val = (Double.parseDouble(txtUp.getText())) * (Double.parseDouble(txtQty.getText()));
          v.add(val);
          dd.addRow(v);
      } else {
          JOptionPane.showMessageDialog(null, "data already exist.");
      }
  }
  </code></pre>