I have this function in the controller class of the relevant fxml. I need this function to be fired on focus out from a textfield, but scene builder doesn't have an event similar to onfocusout. How to achieve this using the control class?
@FXML
private void ValidateBikeNo(){
    Tooltip error = new Tooltip("This bike no exists");
    BikeNoIn.setTooltip(error);
}
You can attach a focusListener to the TextField and then execute the code inside it. The listener can be attached inside the initialize() method of the controller.
public class MyController implements Initializable {
    ...
    @FXML
    private Textfield textField;
    public void initialize() {
        ...
        textField.focusedProperty.addListener((ov, oldV, newV) -> {
           if (!newV) { // focus lost
              // Your code
           }
        });
         .....
    }
}
You have to use method textField.focusedProperty() instead of textField.focusProperty
public class MyController implements Initializable { 
...         
@FXML        
private Textfield textField;
public void initialize() {
   textField.focusedProperty().addListener((ov, oldV, newV) -> {
      if (!newV) { // focus lost
              // Your code
           }
        });
    }
}
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