Community
Participate
Working Groups
Currently, in a FormText object, it is possible to programmatically get the selection. I would like to also be able to set or clear the selection.
New Gerrit change created: https://git.eclipse.org/r/60383
Bug 442108 - Implemented clearSelectionText Method to clear the selection programmatically. A method to programmatically set the selection has not yet been implemented. This change was not properly tested but I successfully use the new method for the intended purpose with the code below: /** * main method for testing and documentation purposes. * * @param args */ public static void main(String[] args) throws Exception { Display display = new Display(); Shell shell = new Shell(display); shell.setSize(300, 300); shell.setLayout(new FillLayout()); FormText t = new FormText(shell, SWT.NONE); t.setText("<content>HUBBAHUBBA</content>", true, false); Button btn = new Button(shell, SWT.PUSH); btn.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); btn.setText("Print Selection"); btn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { System.out.println(t.getSelectionText()); } }); Button btnClear = new Button(t, SWT.PUSH); btnClear.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false)); btnClear.setText("Clear Selection"); btnClear.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { t.clearSelection(); } }); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }