How perform task on JavaFX TextField at onfocus and outfocus?

前端 未结 3 2131
广开言路
广开言路 2020-11-29 08:20

I am working on JavaFX project. I need to perform some task on a JavaFX TextField.

For example on the \"on focus\" event for the TextField

3条回答
  •  执笔经年
    2020-11-29 08:26

    I thought it might be helpful to see an example which specifies the ChangeListener as an anonymous inner class like scottb mentioned.

    TextField yourTextField = new TextField();
    yourTextField.focusedProperty().addListener(new ChangeListener()
    {
        @Override
        public void changed(ObservableValue arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
        {
            if (newPropertyValue)
            {
                System.out.println("Textfield on focus");
            }
            else
            {
                System.out.println("Textfield out focus");
            }
        }
    });
    

    I hope this answer is helpful!

提交回复
热议问题