Balrog
Balrog

Reputation: 47

Select/mark specific word in SWT Textfield

I've got an SWT Textfield with some text which is added automatically. Now I want to select a specific phrase in the text automatically, so that the user could replace this without the manual selection. But all I've found in the api is the selectAll() method, which works but selects ALL the text, not a specific part.

Is there any way to do so?

Upvotes: 0

Views: 52

Answers (1)

Baz
Baz

Reputation: 36904

Text#setSelection(int start, int end) will do what you need.

Example:

Text text = new Text(shell, SWT.BORDER);
text.setText("This is some random text");
text.setSelection(5, 7);

Looks like this:

enter image description here

Upvotes: 1

Related Questions