JavaFX PasswordField Tutorial with Examples

View more Tutorials:

Follow us on our fanpages to receive notifications every time there are new articles. Facebook Twitter

1- JavaFX PasswordField

JavaFX PasswordField is a user control allowing users to enter their password, its contents can be read by application. PasswordField does not display the characters that users enter, instead of that, it displays a circle corresponding to each character typed.

2- PasswordField example


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 {

   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>() {

           public void handle(ActionEvent event) {
               String password = passwordField.getText();

       FlowPane root = new FlowPane();
       root.setPadding(new Insets(10));

       root.getChildren().addAll(label, passwordField, button);

       Scene scene = new Scene(root, 320, 150);

       primaryStage.setTitle("JavaFX PasswordField (o7planning.org)");

   public static void main(String[] args) {


View more Tutorials:

Maybe you are interested

These are online courses outside the o7planning website that we introduced, which may include free or discounted courses.