You want to highlight a portion of the text within a text field.
Selection.setSelection( ) method.
Selection class has a static method,
setSelection( ), which highlights a portion of
the text in the text field. The selection is applied to the text
field that has focus (see Recipe 8.23). The
) method takes two parameters:
The beginning, zero-relative index of the text to highlight
The index of the character after the text to highlight
myTextField.text = "this is some text"; // Set the text value. Selection.setFocus("myTextField"); // Bring focus to the text field. Selection.setSelection(0, 4); // Highlight the word "this".