如何在onfocus和outfocus上对javaFX TextField执行任务? [英] How perform task on javaFX TextField at onfocus and outfocus?
本文介绍了如何在onfocus和outfocus上对javaFX TextField执行任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在研究JavaFX项目。我需要在JavaFX上执行一些任务 TextField
。
I am working on JavaFX project. I need to perform some task on a JavaFX TextField
.
例如关于on focus事件 TextField
我要打印
For example on the "on focus" event for the TextField
I want to print
System.out.println("Textfield on focus");
以及对焦事件应打印
System.out.println("Textfield out focus");
推荐答案
我认为看一个例子可能会有所帮助将ChangeListener指定为匿名内部类,如scottb所述。
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<Boolean>()
{
@Override
public void changed(ObservableValue<? extends Boolean> arg0, Boolean oldPropertyValue, Boolean newPropertyValue)
{
if (newPropertyValue)
{
System.out.println("Textfield on focus");
}
else
{
System.out.println("Textfield out focus");
}
}
});
我希望这个答案有用!
这篇关于如何在onfocus和outfocus上对javaFX TextField执行任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文