Class EnhancedPasswordField
- All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget, javafx.scene.control.Skinnable
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.
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class javafx.scene.control.TextInputControl
javafx.scene.control.TextInputControl.Content -
Property Summary
PropertiesTypePropertyDescriptionfinal javafx.beans.property.ObjectProperty<Character> The character used to mask the password when it is not shown in plain text.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.BooleanPropertyIndicates whether the password is currently shown in plain text.Properties inherited from class javafx.scene.control.TextField
alignment, onAction, prefColumnCountProperties inherited from class javafx.scene.control.TextInputControl
anchor, caretPosition, editable, font, length, promptText, redoable, selectedText, selection, textFormatter, text, undoableProperties inherited from class javafx.scene.control.Control
contextMenu, skin, tooltipProperties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, widthProperties inherited from class javafx.scene.Parent
needsLayoutProperties 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 -
Field Summary
FieldsFields inherited from class javafx.scene.control.TextField
DEFAULT_PREF_COLUMN_COUNTFields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZEFields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected javafx.scene.control.Skin<?> final javafx.beans.property.ObjectProperty<Character> The character used to mask the password when it is not shown in plain text.static List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> final CharacterGets the value of theechoCharproperty.final CharacterRetrieves the echo character property value safely.final javafx.scene.NodegetLeft()Gets the value of theleftproperty.final javafx.scene.NodegetRight()Gets the value of therightproperty.final booleanGets the value of theshowPasswordproperty.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 voidsetEchoChar(Character echoChar) Sets the value of theechoCharproperty.final voidsetLeft(javafx.scene.Node left) Sets the value of theleftproperty.final voidsetRight(javafx.scene.Node right) Sets the value of therightproperty.final voidsetShowPassword(boolean showPassword) Sets the value of theshowPasswordproperty.final javafx.beans.property.BooleanPropertyIndicates whether the password is currently shown in plain text.Methods inherited from class javafx.scene.control.PasswordField
copy, cut, queryAccessibleAttributeMethods inherited from class javafx.scene.control.TextField
alignmentProperty, getAlignment, getCharacters, getOnAction, getPrefColumnCount, onActionProperty, prefColumnCountProperty, setAlignment, setOnAction, setPrefColumnCountMethods 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, undoablePropertyMethods 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, tooltipPropertyMethods 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, widthPropertyMethods inherited from class javafx.scene.Parent
getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBoundsMethods 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, requestFocusTraversal, 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, visiblePropertyMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javafx.css.Styleable
getStyleableNode
-
Property Details
-
left
public final javafx.beans.property.ObjectProperty<javafx.scene.Node> leftPropertyThe 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> rightPropertyThe 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 showPasswordPropertyIndicates 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 tofalse, the password will be masked as usual.- See Also:
-
echoChar
The character used to mask the password when it is not shown in plain text.Can be set via CSS using the
-fx-echo-charproperty. Valid values are: a single character (e.g.'●'). The default value is'●'.- See Also:
-
-
Field Details
-
DEFAULT_ECHO_CHAR
public static final char DEFAULT_ECHO_CHAR- See Also:
-
-
Constructor Details
-
EnhancedPasswordField
public EnhancedPasswordField() -
EnhancedPasswordField
-
-
Method Details
-
createDefaultSkin
protected javafx.scene.control.Skin<?> createDefaultSkin()- Overrides:
createDefaultSkinin classjavafx.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.
- Returns:
- the
leftproperty - See Also:
-
getLeft
public final javafx.scene.Node getLeft()Gets the value of theleftproperty.- 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.
- Returns:
- the value of the
leftproperty - See Also:
-
setLeft
public final void setLeft(javafx.scene.Node left) Sets the value of theleftproperty.- 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.
- Parameters:
left- the value for theleftproperty- See Also:
-
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.
- Returns:
- the
rightproperty - See Also:
-
getRight
public final javafx.scene.Node getRight()Gets the value of therightproperty.- 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.
- Returns:
- the value of the
rightproperty - See Also:
-
setRight
public final void setRight(javafx.scene.Node right) Sets the value of therightproperty.- 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.
- Parameters:
right- the value for therightproperty- See Also:
-
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 tofalse, the password will be masked as usual.- Returns:
- the show password property
- See Also:
-
isShowPassword
public final boolean isShowPassword()Gets the value of theshowPasswordproperty.- 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 tofalse, the password will be masked as usual. - Returns:
- the value of the
showPasswordproperty - See Also:
-
setShowPassword
public final void setShowPassword(boolean showPassword) Sets the value of theshowPasswordproperty.- 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 tofalse, the password will be masked as usual. - Parameters:
showPassword- the value for theshowPasswordproperty- See Also:
-
echoCharProperty
The character used to mask the password when it is not shown in plain text.Can be set via CSS using the
-fx-echo-charproperty. Valid values are: a single character (e.g.'●'). The default value is'●'.- Returns:
- the echo character property
- See Also:
-
getEchoChar
Gets the value of theechoCharproperty.- Property description:
- The character used to mask the password when it is not shown in plain text.
Can be set via CSS using the
-fx-echo-charproperty. Valid values are: a single character (e.g.'●'). The default value is'●'. - Returns:
- the value of the
echoCharproperty - See Also:
-
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
nullor if an error occurs (such as aClassCastExceptionwhen the property value cannot be cast to aCharacter), this method logs a warning and returns the default echo character.- Returns:
- the character to be used as an echo character, or
DEFAULT_ECHO_CHARif the property isnullor an exception occurs
-
setEchoChar
Sets the value of theechoCharproperty.- Property description:
- The character used to mask the password when it is not shown in plain text.
Can be set via CSS using the
-fx-echo-charproperty. Valid values are: a single character (e.g.'●'). The default value is'●'. - Parameters:
echoChar- the value for theechoCharproperty- See Also:
-
getControlCssMetaData
- Overrides:
getControlCssMetaDatain classjavafx.scene.control.TextField
-
getClassCssMetaData
-
getUserAgentStylesheet
- Overrides:
getUserAgentStylesheetin classjavafx.scene.layout.Region
-