要使选项卡从组合变为组合,请将每个组合的选项卡列表设置为您希望在选项卡之后获得焦点的一个控件。例如,复选框:
composite.setTabList(new Control[]{checkButton});
要成为亮点,您的想象力就是极限。你可以改变背景,添加一些边框,你可以命名它。只要组合中的一个控件获得焦点,您只需更新它。
这是一个完整的例子:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout(SWT.VERTICAL));
createElement(shell);
createElement(shell);
createElement(shell);
createElement(shell);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
display.dispose();
}
private static void createElement(final Composite parent) {
final Composite composite = new Composite(parent, SWT.BORDER);
composite.setLayout(new GridLayout(4, false));
final Button checkButton = new Button(composite, SWT.CHECK);
new Label(composite, SWT.NONE);
final Button button1 = new Button(composite, SWT.PUSH);
final Button button2 = new Button(composite, SWT.PUSH);
Listener listener = new Listener() {
@Override
public void handleEvent(Event event) {
for (Control control : parent.getChildren()) {
control.setBackground(null);
}
composite.setBackground(composite.getDisplay().getSystemColor(SWT.COLOR_RED));
if (event.widget == button1 || event.widget == button2) {
checkButton.setFocus();
}
}
};
checkButton.addListener(SWT.FocusIn, listener);
button1.addListener(SWT.FocusIn, listener);
button2.addListener(SWT.FocusIn, listener);
composite.setTabList(new Control[]{checkButton});
}