1

我们有一个自定义控件,它本质上是一个带有标签和按钮的组合。当前,当用户按下“Tab”时,焦点位于按钮上。

如何使合成获得焦点并从焦点中排除按钮?例如,用户应该能够通过所有自定义控件进行选项卡,而不是停留在按钮上。

更新:我们的控件树如下所示:

  • 主窗格
    • 自定义面板1
      • 标签
      • 按钮
    • 自定义面板2
      • 标签
      • 按钮
    • 自定义面板3
      • 标签
      • 按钮

所有 CustomPanel 都属于同一个 Composite 子类。我们需要的是选项卡在这些面板之间循环而不是“看到”按钮(这些是唯一可聚焦的组件)

4

1 回答 1

3

您可以使用 定义 a 的跳位Composite顺序Composite#setTabList(Control[])

这是一个小例子,它将在Buttons之间制表符onethree忽略Buttonstwofour

public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1, false));

    Composite content = new Composite(shell, SWT.NONE);
    content.setLayout(new GridLayout(2, true));
    content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Button one = new Button(content, SWT.PUSH);
    one.setText("One");

    final Button two = new Button(content, SWT.PUSH);
    two.setText("Two");

    final Button three = new Button(content, SWT.PUSH);
    three.setText("Three");

    final Button four = new Button(content, SWT.PUSH);
    four.setText("Four");

    Control[] controls = new Control[] {one, three};

    content.setTabList(controls);

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

编辑:上面的代码可以很容易地转换为适合您的要求。我自己无法测试它,因为Composites 不能聚焦,但你应该明白:

mainPane.setTabList(new Control[] {customPanel1, customPanel2, customPanel3 });

customPanel1.setTabList(new Control[] {});
customPanel2.setTabList(new Control[] {});
customPanel3.setTabList(new Control[] {});
于 2012-10-17T15:34:50.517 回答