要使標籤從複合材料變爲複合材料,請將每個複合材料的標籤列表設置爲一個控制器,您希望在標籤後對其進行聚焦。例如,複選框:
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});
}
能否請您提供一個[SSCCE(http://www.sscce.org),以幫助我們瞭解你的挑戰? – Baz