简体   繁体   English

JavaFX 禁用单个 TextField 上的默认操作

[英]JavaFX disable default action on a single TextField

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.我在 JavaFX 中有一个表单,并且我设置了一个默认按钮,这样每当我在编辑任何文本字段时按 Enter 键时,都会执行绑定到该按钮的操作。 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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM