On-demand decoration shows only after I enter text in one of my TextFields

I want to enable error decorations only after loginBtn clicked. The problem is if there was no text entered first, decorations won’t show. So if I put TextField.setText in initialize(), decorations are shown after click.

    @Override
    public void initialize(URL paramURL, ResourceBundle paramResourceBundle) {

        validationSupport.setErrorDecorationEnabled(false);

        validationSupport.registerValidator(loginTxtField, Validator.createEmptyValidator("empty"));

        validationSupport.registerValidator(passwordTxtField, Validator.createEmptyValidator("empty"));

        loginTxtField.setText("w");
        loginTxtField.setText("");

        loginBtn.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                validationSupport.setErrorDecorationEnabled(true);
            }
        });

After I switch Scene to another and reload my controller, decorations works well but only If I set text in any TextField before switching Scene.

loginBtn.SetOnAction fires on Button click event.

Leave a Reply

avatar
  Subscribe  
Notify of