I'm working on a pos (like openbravo or dolibarr) panel in Java. When a user presses a `JButton` after getting the product info, the product is added to a `JTable`. However, if he presses the button twice or more, the same product is added again, so I could have a `JTable` with 2,3 or 4 same lines. That's why I'm trying to limit that.

My idea, is to compare the cells containing product id in the `JTable` and the variable containing product id in the product info form.

The problem is, when I open the panel for the first time, my `JTable` is empty, so my `if` statement can't work.

I need some advice.

```
jButton1.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
    if(idprod!=0)
    {   
        montanttva1 = prixtotalttc - prixtotalht;
        int row = tableaupan.getRowCount();
        for (int i = 0; i < row; i++){
            int test =(int) (tableaupan.getModel().getValueAt(i,0)); 
            if (test==idprod)
            {
                JOptionPane.showMessageDialog(null, "Product is already in the basket !","Error",JOptionPane.ERROR_MESSAGE);     
            }
            else
            {
            modele.addCaisse(new Caisse(idprod,JTitre.getText().toString(),cqte,prixunittcc,prixht,montanttva1,prixtotalht,prixtotalttc,typetva,tva));
            }
        }
    }
    else
    {
        JOptionPane.showMessageDialog(null, "Nothing to add in the basket !", "Errorr",JOptionPane.ERROR_MESSAGE);                  
    }
}
});

```

Thanks, with your comments I understand my logic error. Now I must add a method like this in my model ? 

```
public boolean containsId(int idprod) {
*condition for true*
return true;
*condition for false*
return false;
}

```