How to set cursor position in SWT text

I am trying to set the position of the SWT Text cursor to the end after adding a line. I know about changing the position of the SWT StyledText cursor, but I'm not sure about SWT Text . If you encounter this challenge and find a solution, share it.

+7
source share
1 answer

Take a look at Text#setSelection(int) :

 public static void main(String[] args) { Display d = new Display(); final Shell shell = new Shell(d); shell.setLayout(new GridLayout(1, false)); Text text = new Text(shell, SWT.BORDER); text.setText("Some random text here..."); text.setSelection(text.getText().length()); shell.pack(); shell.open(); while (!shell.isDisposed()) while (!d.readAndDispatch()) d.sleep(); } 

This will set the cursor to the end.

+17
source

All Articles