Java Reference
In-Depth Information
TextFieldDemo extends RadioButtonDemo (line 7) and adds a label and a text field to
let the user enter a new text (lines 12-19). After you set a new text in the text field and press
the Enter key, a new message is displayed (line 22). Pressing the Enter key on the text field
triggers an action event.
Note
If a text field is used for entering a password, use PasswordField to replace
TextField . PasswordField extends TextField and hides the input text with
echo characters ****** .
PasswordField
16.15
Can you disable editing of a text field?
Check
16.16
Can you apply all the methods for TextInputControl to TextField ?
Point
16.17
Can you set a node as the graphic property in a text field?
16.18
How do you align the text in a text field to the right?
16.7 TextArea
A TextArea enables the user to enter multiple lines of text.
Key
Point
If you want to let the user enter multiple lines of text, you may create several instances of
TextField . A better alternative, however, is to use TextArea , which enables the user to
enter multiple lines of text. Figure 16.13 lists the properties and constructors in TextArea .
The getter and setter methods for property
values and a getter for property itself are provided
in the class, but omitted in the UML diagram for brevity.
javafx.scene.control.TextInputControl
-text: StringProperty
-editable: BooleanProperty
The text content of this control.
Indicates whether the text can be edited by the user.
javafx.scene.control.TextArea
-prefColumnCount: IntegerProperty
-prefRowCount: IntegerProperty
-wrapText: BooleanProperty
Specifies the preferred number of text columns.
Specifies the preferred number of text rows.
Specifies whether the text is wrapped to the next line.
+TextArea()
+TextArea(text: String)
Creates an empty text area.
Creates a text area with the specified text.
F IGURE 16.13
TextArea enables the user to enter or display multiple lines of characters.
Here is an example of creating a text area with 5 rows and 20 columns, wrapped to the next
line, red text color, and Courier font 20 pixels.
TextArea taNote = new TextArea( "This is a text area" );
taNote.setPrefColumnCount( 20 );
taNote.setPrefRowCount( 5 );
taNote.setWrapText( true );
taNote.setStyle( "-fx-text-fill: red" );
taNote.setFont(Font.font( "Times" , 20 ));
 
 
 
Search WWH ::




Custom Search