Hướng dẫn và ví dụ JavaFX PasswordField
Xem thêm các chuyên mục:

Là một website được viết trên công nghệ web Flutter vì vậy hỗ trợ rất tốt cho người học, kể cả những người học khó tính nhất.
Hiện tại website đang tiếp tục được cập nhập nội dung cho phong phú và đầy đủ hơn. Mong các bạn nghé thăm và ủng hộ website mới của chúng tôi.


JavaFX PasswordField là một thành phần giao diện người dùng cho phép người dùng nhập vào mật khẩu, nội dung của nó có thể đọc được bởi ứng dụng. PasswordField không hiển thị các ký tự mà người dùng nhập vào, thay vào đó nó hiển thị dấu hoa thị tương ứng với mỗi ký tự nhập vào.


PasswordFieldDemo.java
package org.o7planning.javafx.passwordfield;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
public class PasswordFieldDemo extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
PasswordField passwordField = new PasswordField();
Button button = new Button("Show Password");
Label label = new Label("?");
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
String password = passwordField.getText();
label.setText(password);
}
});
FlowPane root = new FlowPane();
root.setPadding(new Insets(10));
root.setVgap(5);
root.setHgap(5);
root.getChildren().addAll(label, passwordField, button);
Scene scene = new Scene(root, 320, 150);
primaryStage.setTitle("JavaFX PasswordField (o7planning.org)");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}