Project: SWT
Bug 106511 Cannot set text selection in VerifyListener.verifyText
Reported: 2005-08-09 12:05:17 | Status: resolved fixed

On Linux GTK I cannot set the text selection inside the verifyText() method. In the example below, setting the text works correctly, so why not setting the selection? import org.eclipse.swt.SWT; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class TestSetSelectionInVerify { private static VerifyListener lnr; public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout()); final Text text = new Text(shell, SWT.BORDER); text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); lnr = new VerifyListener() { public void verifyText(VerifyEvent evt) { evt.doit = false; text.removeVerifyListener(lnr); text.setText("Hello"); text.setSelection(1, 3); text.addVerifyListener(lnr); } }; text.addVerifyListener(lnr); shell.setSize(300, 200); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); } }

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java