简体   繁体   English

如何从SWT小部件控件(如文本)上移开焦点?

[英]How do you remove focus from an SWT widget control (such as Text)?

I know that we can use setFocus() to set a keyboard focus on a control object such as text . 我知道我们可以使用setFocus()在诸如text之类的控件对象上设置键盘焦点。

What can we do to remove the focus from the same object, reversing this function's effect? 我们该怎么做才能从同一对象上移开焦点,从而反转该函数的作用?

You cannot remove the focus from a Control , ie unfocus it. 您不能从Control移开焦点,也不能使其失去焦点。

As @Baz suggests, you can transfer the focus to another control with setFocus() or forceFocus() . 正如@Baz所建议的,您可以使用setFocus()forceFocus()将焦点转移到另一个控件。 The latter gives focus to a Control even if it has the SWT.NO_FOCUS style, like Label s do. 后者即使具有SWT.NO_FOCUS样式(如Label的样式),也将焦点放在Control

You can remove/transfer focus from a SWT Control(Text) in the following 2 ways: 您可以通过以下两种方式从SWT控件(文本)中删除/转移焦点:

  • Set the focus on some other Control using the setFocus() method. 使用setFocus()方法将焦点设置在其他控件上。
  • You can disable the Control widget by using setEnabled(false) method, but this will deprive the widget of its functionality. 您可以使用setEnabled(false)方法禁用“控制”小部件,但是这将使小部件失去其功能。 Hence it's not recommended. 因此,不建议使用。

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

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