Home  >  Article  >  Java  >  TextField

TextField

PHPz
PHPzOriginal
2024-07-16 03:38:10379browse

A text field can be used to enter or display a string. TextField is a subclass of TextInputControl. Figure below lists the properties and constructors in TextField.

Image description

Here is an example of creating a noneditable text field with red text color, a specified font, and right horizontal alignment:

TextField tfMessage = new TextField("T-Strom");
tfMessage.setEditable(false);
tfMessage.setStyle("-fx-text-fill: red");
tfMessage.setFont(Font.font("Times", 20));
tfMessage.setAlignment(Pos.BASELINE_RIGHT);

Image description

When you move the cursor in the text field and press the Enter key, it fires an ActionEvent. The code below gives a program that adds a text field to the preceding example to let the user set a new message, as shown in Figure below.

Image description

Image description

TextFieldDemo extends RadioButtonDemo (line 9) and adds a label and a text field to let the user enter a new text (lines 14–21). After you set a new text in the text field and press the Enter key, a new message is displayed (line 24). Pressing the Enter key on the text field triggers an action event.

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 ******.

The above is the detailed content of TextField. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn