"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > TextField

TextField

Published on 2024-07-31
Browse:172

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

Release Statement This article is reproduced at: https://dev.to/paulike/textfield-4jgh?1 If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3