Java Reference
In-Depth Information
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.TextField
-alignment: ObjectProperty<Pos>
-prefColumnCount: IntegerProperty
-onAction:
ObjectProperty<EventHandler<ActionEvent>>
Specifies how the text should be aligned in the text field.
Specifies the preferred number of columns in the text field.
Specifies the handler for processing the action event on the
text field.
+TextField()
+TextField(text: String)
Creates an empty text field.
Creates a text field with the specified text.
F
IGURE
16.11
TextField
enables the user to enter or display a string.
Application
ButtonDemo
CheckBoxDemo
F
IGURE
16.12
The program demonstrates using text fields.
RadioButtonDemo
3
import
javafx.scene.control.Label;
4
import
javafx.scene.control.TextField;
5
import
javafx.scene.layout.BorderPane;
6
7
public class
TextFieldDemo
extends
RadioButtonDemo {
8 @Override
// Override the getPane() method in the super class
9
protected
BorderPane getPane() {
10 BorderPane pane =
super
.getPane();
11
12 BorderPane paneForTextField =
new
BorderPane();
13 paneForTextField.setPadding(
new
Insets(
5
,
5
,
5
,
5
));
14 paneForTextField.setStyle(
"-fx-border-color: green"
);
15 paneForTextField.setLeft(
new
Label(
"Enter a new message: "
));
16
17 TextField tf =
new
TextField();
18 tf.setAlignment(Pos.BOTTOM_RIGHT);
19 paneForTextField.setCenter(tf);
20 pane.setTop(paneForTextField);
21
22
TextFieldDemo
override
getPane()
invoke
super.getPane()
pane for label and text field
create text field
add to border pane
tf.setOnAction(e -> text.setText(tf.getText()));
handle text field action
23
24
return
pane;
return border pane
25 }
26 }
main method omitted
Search WWH ::
Custom Search