Search code examples
javajavafxfocus

JavaFX relative to Swing setFocusable(true/false)?


I am trying to find some way to make an UI Control unfocusabe in JavaFX:

Is there something similar to Swing or do I have to override some method?

UPDATE:

I want to make the control not focusable at all and not change the focus to another Node.

What you can do is:

node.setFocusTraversable(false);

Solution

  • On the Node from basically every Control inherits the focusProperty(). You can bind something to that property or add a ChangeListener to detect when focus is lost:

    focusedProperty().addListener((observalbe, oldFocusedState, newFocusedState) -> {
      System.out.println("Control changed focused state from "+oldFocusedState+"->"+newFocusedState);
    });