Class EnhancedPasswordField

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
javafx.scene.control.TextInputControl
javafx.scene.control.TextField
javafx.scene.control.PasswordField
com.dlsc.gemsfx.EnhancedPasswordField
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget, javafx.scene.control.Skinnable

public class EnhancedPasswordField extends javafx.scene.control.PasswordField
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:

  • Customizable echo character: The character used to mask the password can be customized.
  • Toggle password visibility: Users can toggle between hiding and showing the password as plain text.
  • Left and right nodes: Allows adding custom nodes (like buttons or icons) to either side of the field.
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
  • Property Summary

    Properties
    Type
    Property
    Description
    final javafx.beans.property.ObjectProperty<Character>
     
    final javafx.beans.property.ObjectProperty<javafx.scene.Node>
    The node to be shown on the left side of the password field.
    final javafx.beans.property.ObjectProperty<javafx.scene.Node>
    The node to be shown on the right side of the password field.
    final javafx.beans.property.BooleanProperty
    Indicates whether the password is currently shown in plain text.

    Properties inherited from class javafx.scene.control.TextField

    alignment, onAction, prefColumnCount

    Properties inherited from class javafx.scene.control.TextInputControl

    anchor, caretPosition, editable, font, length, promptText, redoable, selectedText, selection, textFormatter, text, undoable

    Properties inherited from class javafx.scene.control.Control

    contextMenu, skin, tooltip

    Properties inherited from class javafx.scene.layout.Region

    background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width

    Properties inherited from class javafx.scene.Parent

    needsLayout

    Properties inherited from class javafx.scene.Node

    accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, focusVisible, focusWithin, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
  • Nested Class Summary

    Nested classes/interfaces inherited from class javafx.scene.control.TextInputControl

    javafx.scene.control.TextInputControl.Content
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final char
     

    Fields inherited from class javafx.scene.control.TextField

    DEFAULT_PREF_COLUMN_COUNT

    Fields inherited from class javafx.scene.layout.Region

    USE_COMPUTED_SIZE, USE_PREF_SIZE

    Fields inherited from class javafx.scene.Node

    BASELINE_OFFSET_SAME_AS_HEIGHT
  • Constructor Summary

    Constructors
    Constructor
    Description
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected javafx.scene.control.Skin<?>
     
    final javafx.beans.property.ObjectProperty<Character>
     
    static List<javafx.css.CssMetaData<? extends javafx.css.Styleable,?>>
     
    List<javafx.css.CssMetaData<? extends javafx.css.Styleable,?>>
     
    final Character
    Gets the value of the property echoChar.
    final Character
    Retrieves the echo character property value safely.
    final javafx.scene.Node
    Gets the value of the property left.
    final javafx.scene.Node
    Gets the value of the property right.
     
    final boolean
    Gets the value of the property showPassword.
    final javafx.beans.property.ObjectProperty<javafx.scene.Node>
    The node to be shown on the left side of the password field.
    final javafx.beans.property.ObjectProperty<javafx.scene.Node>
    The node to be shown on the right side of the password field.
    final void
    Sets the value of the property echoChar.
    final void
    setLeft(javafx.scene.Node left)
    Sets the value of the property left.
    final void
    setRight(javafx.scene.Node right)
    Sets the value of the property right.
    final void
    setShowPassword(boolean showPassword)
    Sets the value of the property showPassword.
    final javafx.beans.property.BooleanProperty
    Indicates whether the password is currently shown in plain text.

    Methods inherited from class javafx.scene.control.PasswordField

    copy, cut, queryAccessibleAttribute

    Methods inherited from class javafx.scene.control.TextField

    alignmentProperty, getAlignment, getCharacters, getOnAction, getPrefColumnCount, onActionProperty, prefColumnCountProperty, setAlignment, setOnAction, setPrefColumnCount

    Methods inherited from class javafx.scene.control.TextInputControl

    anchorProperty, appendText, backward, cancelEdit, caretPositionProperty, clear, commitValue, deleteNextChar, deletePreviousChar, deleteText, deleteText, deselect, editableProperty, end, endOfNextWord, executeAccessibleAction, extendSelection, fontProperty, forward, getAnchor, getCaretPosition, getContent, getFont, getLength, getPromptText, getSelectedText, getSelection, getText, getText, getTextFormatter, home, insertText, isEditable, isRedoable, isUndoable, lengthProperty, nextWord, paste, positionCaret, previousWord, promptTextProperty, redo, redoableProperty, replaceSelection, replaceText, replaceText, selectAll, selectBackward, selectedTextProperty, selectEnd, selectEndOfNextWord, selectForward, selectHome, selectionProperty, selectNextWord, selectPositionCaret, selectPreviousWord, selectRange, setEditable, setFont, setPromptText, setText, setTextFormatter, textFormatterProperty, textProperty, undo, undoableProperty

    Methods inherited from class javafx.scene.control.Control

    computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, getBaselineOffset, getContextMenu, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty

    Methods inherited from class javafx.scene.layout.Region

    backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty

    Methods inherited from class javafx.scene.Parent

    getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds

    Methods inherited from class javafx.scene.Node

    accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, focusVisibleProperty, focusWithinProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isFocusVisible, isFocusWithin, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javafx.css.Styleable

    getStyleableNode
  • Property Details

    • left

      public final javafx.beans.property.ObjectProperty<javafx.scene.Node> leftProperty
      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.

      See Also:
    • right

      public final javafx.beans.property.ObjectProperty<javafx.scene.Node> rightProperty
      The node to be shown on the right side of the password field.

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

      See Also:
    • showPassword

      public final javafx.beans.property.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.

      See Also:
    • echoChar

      public final javafx.beans.property.ObjectProperty<Character> echoCharProperty
      See Also:
  • Field Details

  • Constructor Details

    • EnhancedPasswordField

      public EnhancedPasswordField()
    • EnhancedPasswordField

      public EnhancedPasswordField(String text)
  • Method Details

    • createDefaultSkin

      protected javafx.scene.control.Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class javafx.scene.control.TextField
    • leftProperty

      public final javafx.beans.property.ObjectProperty<javafx.scene.Node> leftProperty()
      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.

      See Also:
    • getLeft

      public final javafx.scene.Node getLeft()
      Gets the value of the property left.
      Property description:
      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.

    • setLeft

      public final void setLeft(javafx.scene.Node left)
      Sets the value of the property left.
      Property description:
      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.

    • rightProperty

      public final javafx.beans.property.ObjectProperty<javafx.scene.Node> rightProperty()
      The node to be shown on the right side of the password field.

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

      See Also:
    • getRight

      public final javafx.scene.Node getRight()
      Gets the value of the property right.
      Property description:
      The node to be shown on the right side of the password field.

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

    • setRight

      public final void setRight(javafx.scene.Node right)
      Sets the value of the property right.
      Property description:
      The node to be shown on the right side of the password field.

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

    • showPasswordProperty

      public final javafx.beans.property.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.

      See Also:
    • isShowPassword

      public final boolean isShowPassword()
      Gets the value of the property showPassword.
      Property description:
      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.

    • setShowPassword

      public final void setShowPassword(boolean showPassword)
      Sets the value of the property showPassword.
      Property description:
      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.

    • echoCharProperty

      public final javafx.beans.property.ObjectProperty<Character> echoCharProperty()
      See Also:
    • getEchoChar

      public final Character getEchoChar()
      Gets the value of the property echoChar.
      Property description:
    • getEchoCharSafe

      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:
      the character to be used as an echo character, or DEFAULT_ECHO_CHAR if the property is null or an exception occurs
    • setEchoChar

      public final void setEchoChar(Character echoChar)
      Sets the value of the property echoChar.
      Property description:
    • getControlCssMetaData

      public List<javafx.css.CssMetaData<? extends javafx.css.Styleable,?>> getControlCssMetaData()
      Overrides:
      getControlCssMetaData in class javafx.scene.control.TextField
    • getClassCssMetaData

      public static List<javafx.css.CssMetaData<? extends javafx.css.Styleable,?>> getClassCssMetaData()
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Overrides:
      getUserAgentStylesheet in class javafx.scene.layout.Region