Reputation: 33
I have an Java SWT Text which I set a long text to. When the shell opens, I want the text to be focused at the end so the user can se the ending of the text.
This is what I got:
Text text = new Text(new Group(parent, SWT.NONE), SWT.BORDER | SWT.SINGLE);
text.setText(someLongText);
text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
I tried with SWT.RIGHT but it didnt help.
To illustrate what I mean, I used the save functionality in MS Paint. The first picture is what I want to achieve. The second is what I get.
Upvotes: 0
Views: 468
Reputation: 111142
You can set the selection to the end of the text:
text.setSelection(text.getText().length());
Testing on macOS this only works if the Text
has the SWT.MULTI
style rather than SWT.SINGLE
but on other platforms it might work with SWT.SINGLE
.
Upvotes: 1