mercredi 21 décembre 2016

javafx checkbox handle the event on the same object that generates it

I have a code like this:

CheckBox checkboxFrame1;

    checkboxFrame1.setOnMousePressed(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent event) {
            CheckBox chk = (CheckBox) event.getSource();
            if (!chk.isSelected()) 
            {
                if (makeNotSelected()) {
                     chk.setSelected(false);
                }
            }
        }

    });

or another version:

checkboxFrame1.selectedProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (makeNotSelected()) {
                     checkboxFrame1.setSelected(false);
            }
        }
    });

Both of these codes do not work. I think that they do not work to avoid race conditions.

How can I use an event that changes the status (selected or not) of the object - checkbox - that caused it ?




Aucun commentaire:

Enregistrer un commentaire