user3583533
user3583533

Reputation: 1

SWT text box auto-selected for users to enter info

I am building a game and the users are supposed to enter information into an SWT Text widget. However, each time they want to enter they have to click on the Text widget in order to be able to enter their score. I want to make it so that the proper Text widget is selected at the proper time so that the users can simply enter the score and press enter without having to touch a mouse. I already have the

    shell.setDefaultButton(submitButton);

submit button made top priority for that aspect, I just don't know how to make the right text selected.

Upvotes: 0

Views: 308

Answers (1)

Baz
Baz

Reputation: 36904

This should do:

text.forceFocus();
text.selectAll();

This will first force the focus on the Text, i.e. making it the focus widget and then it will select all the text that might already be in there, so the user can just start typing.

Upvotes: 1

Related Questions