Top Description Inners Fields Constructors Methods
com.dlsc.gemsfx

public Class EnhancedPasswordField

extends PasswordField
Class Inheritance
Imports
com.dlsc.gemsfx.skins.EnhancedPasswordFieldSkin, com.dlsc.gemsfx.util.EchoCharConverter, .UIUtil, javafx.beans.property.BooleanProperty, .ObjectProperty, .SimpleBooleanProperty, .SimpleObjectProperty, javafx.css.CssMetaData, .PseudoClass, .Styleable, .StyleableObjectProperty, .StyleableProperty, javafx.scene.Node, javafx.scene.control.PasswordField, .Skin, javafx.scene.input.MouseEvent, javafx.scene.layout.Region, .StackPane, java.util.ArrayList, .Collections, .List, .Objects, java.util.logging.Level, .Logger

A custom password field that enhances the standard PasswordField with additional features.

This component allows for the display of icons or nodes on both the left and right sides of the password field. It also provides the capability to toggle the visibility of the password, allowing the password to be shown as plain text or masked with a customizable echo character. The echo character and visibility can be styled and controlled through CSS or programmatically.

Key features:

Usage example:
EnhancedPasswordField passwordField = new EnhancedPasswordField();
passwordField.setLeft(new ImageView(new Image("path/to/icon.png")));
passwordField.setRight(new Button("Show", e -> passwordField.setShowPassword(!passwordField.isShowPassword())));

See Also
PasswordField

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public static final char
private static final boolean
private static final String
private ObjectProperty<Character>
private final ObjectProperty<Node>
left

Hides javafx.scene.Parent.left.

The node to be shown on the left side of the password field.
private final Logger
private final ObjectProperty<Node>
right

Hides javafx.scene.Parent.right.

The node to be shown on the right side of the password field.
private static final PseudoClass
private BooleanProperty

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.TextField.createDefaultSkin.

Create a new instance of the default skin for this control.

public final ObjectProperty<Character>
public static List<CssMetaData<? extends Styleable, ?>>
getClassCssMetaData()

Hides javafx.scene.control.TextField.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public List<CssMetaData<? extends Styleable, ?>>
getControlCssMetaData()

Overrides javafx.scene.control.TextField.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

public final Character
public final Character

Returns:

the character to be used as an echo character, or DEFAULT_ECHO_CHAR if the property is null or an exception occurs
getEchoCharSafe
()

Retrieves the echo character property value safely.

public final Node
public final Node
public String
getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method.

public final boolean
public final ObjectProperty<Node>
public final ObjectProperty<Node>
public final void
public final void
setLeft(Node left)

public final void
setRight(Node right)

public final void
setShowPassword(boolean showPassword)

public final BooleanProperty

Returns:

the show password property
showPasswordProperty
()

Indicates whether the password is currently shown in plain text.

Inherited from javafx.scene.control.PasswordField:
copycutqueryAccessibleAttribute

Field Detail

DEFAULT_ECHO_CHARback to summary
public static final char DEFAULT_ECHO_CHAR
DEFAULT_SHOW_PASSWORDback to summary
private static final boolean DEFAULT_SHOW_PASSWORD
DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS
echoCharPropertyback to summary
private ObjectProperty<Character> echoCharProperty
leftback to summary
private final ObjectProperty<Node> left

Hides javafx.scene.Parent.left.

The node to be shown on the left side of the password field.

returns the node to be shown on the left side of the password field.

LOGback to summary
private final Logger LOG
SHOWING_PASSWORD_PSEUDO_CLASSback to summary
private static final PseudoClass SHOWING_PASSWORD_PSEUDO_CLASS
showPasswordback to summary
private BooleanProperty showPassword

Constructor Detail

EnhancedPasswordFieldback to summary
public EnhancedPasswordField()
EnhancedPasswordFieldback to summary
public EnhancedPasswordField(String text)

Method Detail

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.TextField.createDefaultSkin.

Doc from javafx.scene.control.TextField.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
echoCharPropertyback to summary
public final ObjectProperty<Character> echoCharProperty()
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.TextField.getClassCssMetaData.

Doc from javafx.scene.control.TextField.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

getControlCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Overrides javafx.scene.control.TextField.getControlCssMetaData.

Doc from javafx.scene.control.TextField.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

Annotations
@Override
getEchoCharback to summary
public final Character getEchoChar()
getEchoCharSafeback to summary
public final Character getEchoCharSafe()

Retrieves the echo character property value safely.

This method provides a safe way to access the echo character. It ensures that if the property is not set or an exception occurs during retrieval, a default echo character will be returned. This approach prevents the application from crashing due to unhandled exceptions and ensures that there is always a valid character returned.

If the property value is null or if an error occurs (such as a ClassCastException when the property value cannot be cast to a Character), this method logs a warning and returns the default echo character.

Returns:Character

the character to be used as an echo character, or DEFAULT_ECHO_CHAR if the property is null or an exception occurs

getLeftback to summary
public final Node getLeft()
getRightback to summary
public final Node getRight()
getUserAgentStylesheetback to summary
public String getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

Doc from javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method. These styles are used in addition to whatever user-agent stylesheets are in use. This provides a mechanism for third parties to introduce styles for custom controls.

The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL does not have a [scheme:] component, the URL is considered to be the [path] component only. Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to the root of the application's classpath.

Subclasses overriding this method should not assume any particular implementation approach as to the number and frequency with which it is called. For this reason, attempting any kind of dynamic implementation (i.e. returning different user agent stylesheet values) based on some state change is highly discouraged, as there is no guarantee when, or even if, this method will be called. Some JavaFX CSS implementations may choose to cache this response for an indefinite period of time, and therefore there should be no expectation around when this method is called.



package com.example.javafx.app;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MyApp extends Application {

    @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        scene.getStylesheets().add("/com/example/javafx/app/mystyles.css");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
For additional information about using CSS with the scene graph, see the CSS Reference Guide.
Annotations
@Override
isShowPasswordback to summary
public final boolean isShowPassword()
leftPropertyback to summary
public final ObjectProperty<Node> leftProperty()
rightPropertyback to summary
public final ObjectProperty<Node> rightProperty()
setEchoCharback to summary
public final void setEchoChar(Character echoChar)
setLeftback to summary
public final void setLeft(Node left)
setRightback to summary
public final void setRight(Node right)
setShowPasswordback to summary
public final void setShowPassword(boolean showPassword)
showPasswordPropertyback to summary
public final BooleanProperty showPasswordProperty()

Indicates whether the password is currently shown in plain text.

This property can be used to toggle the visibility of the password. If set to true, the password will be shown in plain text. If set to false, the password will be masked as usual.

Returns:BooleanProperty

the show password property

com.dlsc.gemsfx back to summary

private Class EnhancedPasswordField.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<EnhancedPasswordField, Character>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ECHO_CHARback to summary
private static final CssMetaData<EnhancedPasswordField, Character> ECHO_CHAR
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()