I am trying to write some code to determine whether or not my checkbox is ticked, I am aware I can write something like to change its state to checked
checkbox.setSelected(true);
But I want to write something along the lines of
if(checkbox.setSelected(true)){
write login-username to config file
} else {
clear the config file
}
How would I go about doing this? I've been trauling through Oracle documentation but have yet to find anything useful
thanks.
you could use .isSelected() to find out if the checkbox is Ticked.
if(checkbox.isSelected()){
write login-username to config file
} else {
clear the config file
}
Have you tried registering a listener to the "selected" property of the checkbox? It would look something like this:
yourCheckbox.selectedProperty().addListener(new ChangeListener<Boolean>() {
@Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
// TODO Auto-generated method stub
if(newValue){
// your checkbox has been ticked.
// write login-username to config file
}else{
// your checkbox has been unticked. do stuff...
// clear the config file
}
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With