【问题标题】:the focus sticks on the shell and it Traverses by tab key no more焦点停留在外壳上,不再按 Tab 键遍历
【发布时间】:2018-04-30 20:55:34
【问题描述】:

我用 SWT 制作了一个简单的 shell 内容,有两个按钮。
编译下面的代码后,当我在外壳上按 Tab 键几次时,焦点从按钮一遍历到按钮二,然后转到外壳(平面)上;尽管按了 Tab 键,但焦点仍停留在那里,不再遍历。
而外壳的样式是 NO_FOCUS。
有人可以告诉我这个问题应该如何解决吗?

我正在使用:Windows 10 64 位、Java 8 64 位、swt v4.7.3、Eclipse neon(java SEE 开发人员),

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.layout.RowData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class MainWindows {
MainWindows() {
Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM | SWT.CENTER | SWT.NO_FOCUS | SWT.TOP);
shell.setText("test win");
shell.setLayout(new RowLayout());
shell.setSize(500, 500);
Button b1 = new Button(shell, SWT.PUSH);
Button b2 = new Button(shell, SWT.PUSH);
b1.setBounds(100, 100, 50, 50);
b2.setBounds(200, 200, 50, 50);
b1.setText("b1");
b2.setText("b2");
shell.open();

while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}

display.dispose();
}
      static void main(String[] args) {
MainWindows mainWindows = new MainWindows();
}
}

【问题讨论】:

  • 注意:SWT.NO_FOCUS 不是Shell 的有效样式,仅支持JavaDoc for Shell 中列出的样式。

标签: java swt


【解决方案1】:

我注意到,出现此问题是因为 Style SWT.CENTER 被错误地用作 Shell 构造函数的参数。
Style CENTER 是用于对齐小部件使用的中心行为的常量: Button Label TableColumn 和 FormLayout 中的 FormAttachment
参考:Class SWT

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-13
    • 1970-01-01
    • 1970-01-01
    • 2013-10-02
    相关资源
    最近更新 更多