Function that checks if a string exists in a Jtable #Java #jTable #Search
public boolean DoesitExistinTable(JTable table, String string, String message) {
boolean exists = false;
ArrayList<String> contentList = new ArrayList();
int row = table.getRowCount();
int column = table.getColumnCount();
for (int i=0; i < jTable1.getRowCount(); i++) { //rows
for (int j=0; j < jTable1.getColumnCount(); j++) { //columns
if (table.getValueAt(i,j)!=null) {
String check = table.getValueAt(i, j).toString().trim();
if (!contentList.contains(string)) {
contentList.add(check);
continue;
}
if (contentList.contains(string)){
exists = true;
JOptionPane.showMessageDialog(null, message,"message",JOptionPane.PLAIN_MESSAGE);
break;
}
} else if (table.getValueAt(i,j) == null) {
continue;
}
}
}
return exists;
}