0

I have a JTable that I add rows to by hit of a button after the user fills out the text fields. What I want to do is make sure that they will not have two rows with the same ID. I attempted to do this by using a while statement to compare there entered value to all values in that column of the JTable. The problem is that even if the String is the same value the program says they are not. I will post my code below. If you have any questions feel free to ask and thanks for the help.

addRow.addActionListener(new ActionListener() 
    {
        @Override
        public void actionPerformed(ActionEvent e) 
        {
            DefaultTableModel model = (DefaultTableModel) database.getModel();

            boolean error = false;
            String test = "";
            int row = 0;

            while(row < rowCount && rowCount > 0)
            {
                test = model.getValueAt(row, 2).toString();
                if(test != IDTF.getText().toString())
                {
                    row++;
                }
                else
                {
                    error = true;
                    break;
                }
            }

            if(priceITF.CheckErrorCode() == false && error == false)
            {
                model.addRow(new Object[]{customerTF.getText().toString(),partNumTF.getText().toString(),
                        IDTF.getText().toString(),priceITF.getText().toString(),delete});
                System.out.println(model.getValueAt(row, 2).toString());
                rowCount++;
            }
            else
            {
                System.out.println("Error");
            }
        }
    });
Ardel
  • 165
  • 3
  • 14

0 Answers0