DekGenius.com
[ Team LiB ] Previous Section Next Section

Recipe 8.17 Formatting User-Input Text

8.17.1 Problem

You want to apply formatting to text as it is entered into a text field by the user.

8.17.2 Solution

Apply a TextFormat object using the setNewTextFormat( ) method of the text field.

8.17.3 Discussion

You should use the setNewTextFormat( ) method of a text field object to apply text formatting to text as it is entered by the user. You should create a TextFormat object as in Recipe 8.16 and then pass that object to the text field's setNewTextFormat( ) method:

myTextFormat = new TextFormat(  );
myTextFormat.color = 0x0000FF;      // Make the text blue.
myTextField.setNewTextFormat(myTextFormat);

When you use setNewTextFormat( ), the formatting is applied to text that the user types into the field.

8.17.4 See Also

Recipe 8.18

    [ Team LiB ] Previous Section Next Section