Frage

It seems me to be so tired and silly now :) I want to fire button pressing event when certain condition is met. Here's my code:

@FXML protected void play(ActionEvent event) throws Exception {

        if(menu.getText().equals("The certain text")) {
            play.fireEvent(event); //Trying to cancel event
        }
}

And when I press the button with fx:id "play", the app hangs. What am I doing wrong? Big thanks!

War es hilfreich?

Lösung

It is entering to the infinite loop. You are firing the event again in the event handler. However check the output log, there should be some exception thrown like "StackOverflowError", since the resources are not infinite :). So do not fire the event in the handler which can handle it again.

Andere Tipps

If you want to cancel the event, use event.consume() it will cause the action to stop.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top