How to validate and return a message if the CheckBox and RadioButton components are not selected in an application? JAVA
How to validate and return a message if the CheckBox and RadioButton components are not selected in an application? JAVA
In CheckBox
and RadioButton
there is a method that can be used to do this test, isSelected()
that returns true
if your component is selected.
In this way you can use it to show your message, you just have to deny this test before.
if (!seuCheckBox.isSelected()) {
System.out.println("checkbox não foi selecionado");
JOptionPane.showMessageDialog(this, "Checkbox não foi Selecionado");
}
In android this same method is named isChecked
if (!seuCheckBox.isChecked()) {
Toast.makeText(getActivity(), "checkbox não selecionado",
Toast.LENGTH_LONG).show();
}