您可以使用Composite#setTabList(Control[])
定義Composite
的選項卡順序。
這裏是將在Button
小號one
和three
之間標籤忽略Button
小號two
和four
一個小例子:
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();
}
EDIT:上述代碼可以很容易地被轉換成適合您的要求。我自己無法測試,因爲Composite
s不是專注的,但你應該明白:
mainPane.setTabList(new Control[] {customPanel1, customPanel2, customPanel3 });
customPanel1.setTabList(new Control[] {});
customPanel2.setTabList(new Control[] {});
customPanel3.setTabList(new Control[] {});
來源
2012-10-17 15:34:50
Baz
這種方法的好處是什麼?當用戶選擇下一個「Composite」時,他/她能夠做什麼而不關注「Widget」? – Baz
@Baz我們將在另一個組件中顯示一些數據並接受鍵盤輸入。 – Eugene