Community
Participate
Working Groups
Build Identifier: M20100211-1343 When trying to set initial focus on a CCombo during creation of cotrols, it does not work. The reason is IMHO that it does not override forceFocus() method, which is used when restoring saved focus from shell. Reproducible: Always
Snippet showing the problem: public class Bug320636 { public static void main(String[] args) { Display display = new Display(); final Shell shell = new Shell(display); shell.setLayout(new GridLayout()); Text textbox = new Text(shell, SWT.SINGLE | SWT.LEAD | SWT.BORDER); textbox.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); textbox.setText("textbox"); CCombo combo = new CCombo(shell, SWT.FLAT | SWT.BORDER); combo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); for (int i = 0; i < 5; i++) { combo.add("item" + i); } combo.setText("item0"); combo.setFocus (); shell.pack(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }
Created attachment 188310 [details] patch CCombo.setFocus() should set focus on the text and this happens when text.setFocus() is called. But, we return before text.setFocus() is called because the CCombo's parent is not yet visible and isVisible() returns false. The patch uses getVisible() instead of isVisible(). Carolyn, can you please review the patch?
Looks good, Lakshmi - go for it!
Thanks Carolyn! Fixed in HEAD > 20110209