选择/取消选择JavaFX中的文本字段

huangapple go评论67阅读模式
英文:

Select/deselect TextField in JavaFX

问题

我有一个项目,其中包含5个文本字段,问题是当程序启动时,第一个文本字段总是被光标“选定”了?

如何去除这个选定状态?我已经尝试过了...

  1. textfield.clear() / 它只会清除内容,但默认情况下它是空的
  2. textfield.setDisabled(true) / 我无法选择或编辑它
  3. textfield.setEditable(false) / 我无法编辑
  4. textfield.deselect() / 实际上这什么也没做

有什么想法吗?

英文:

I have a project, that contains 5 textfields, and the problem is that when the program starts, the first textfield is always "selected" with a cursor in it?

选择/取消选择JavaFX中的文本字段

How should I remove the selection? I have tried..

  1. textfield.clear() / it only clear the content, but it is empty by default
  2. textfield.setDisabled(true) / I can't select or edit it at all
  3. textfield.setEditable(false) / I can't edit
  4. textfield.deselect() / actually this doesn't do anything

Any idea?

答案1

得分: 2

尝试在父级中使用 root.requestFocus();

英文:

Try root.requestFocus(); in the parent.

huangapple
  • 本文由 发表于 2020年4月7日 05:09:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/61069027.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定