Am having a method that check all JTextField
s in a panel JPanel
to see whether they are empty, am iterating through all the components in the container. in the container i have labels, text fields and combo boxes. So i can be able validate the first few JTextField
s but when i encounter the first JComboBox<?>
the validation stop and i don't seem to understand why. Below is the code :-
private boolean validateInputFields(JPanel container) {
for (Component comp : container.getComponents()) {
if (comp instanceof JTextField) {
JTextField temp = (JTextField) comp;
if (temp.getText().trim().equals("")) {
changeComponentProperties(temp);
return true;
} else{
temp.setBackground(Color.WHITE);
temp.setForeground(Color.BLACK);
}
}
}
return false;
}
Any assistance will be highly appreciated.
Also note that this is invoked when a button (say save button) is clicked.