I have a form in JavaFX and I have setup a default button so that whenever I press enter while editing any of the text fields the action bound to the button is performed. The issue that I have is that I would like to disable this behavior on a single text field, and I could not find a solution to this.
Thanks in advance for any suggestion.
EDIT: I found out that using
inputField.onActionProperty().set()
instead of
inputField.onActionProperty().addListener()
works
You should be able to retrieve the event target and check if it's the one that should be avoided, something like this.
final EventTarget target = event.getTarget();
if (code == KeyCode.ENTER && target instanceof TextField) {
// Do casting stuff then...
if(target != myTextField)
doSomething();
else
dont();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.