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
io.github.palexdev.materialfx.controls.MFXTextField
io.github.palexdev.materialfx.controls.MFXPasswordField
- All Implemented Interfaces:
MFXMenuControl,Validated,Styleable,EventTarget,Skinnable
This is my implementation of a password field, a TextField which masks the given input text.
Extends
MFXTextField, starts with a default trailing icon which allows to show/hide the password and it's
defined by the defaultTrailingIcon() method so it can be changed after instantiation or by overriding the method.
Specific features:
- Allows to change the "mask" character, even at runtime
- Allows to show/hide the password.
- Allows to copy the selected text (Ctrl + C)
- Allows to cut the selected text (Ctrl + X)
- Allows to paste the text in the clipboard to the field (Ctrl + V)
- Allows to enable/disable copy, cut and paste at any time
- Introduces a new PseudoClass, ":masked" that activates when the text is masked
-
Property Summary
PropertiesTypePropertyDescriptionSpecifies if copying the password field text is allowed.Specifies if it's allowed to cut text from the password field.Specifies if it's allowed to paste text from the clipboard to the field.Specifies the character used to mask the text.Specifies if the text should be un-masked to show the password.Properties inherited from class io.github.palexdev.materialfx.controls.MFXTextField
allowEdit, animated, borderGap, caretVisible, delegateAnchor, delegateCaretPosition, delegateFocused, delegateRedoable, delegateSelectedText, delegateSelection, delegateTextFormatter, delegateUndoable, floating, floatingTextGap, floatingText, floatMode, graphicTextGap, leadingIcon, measureUnitGap, measureUnit, scaleOnAbove, selectable, textFill, textLimit, trailingIconProperties 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, 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
TextInputControl.Content -
Field Summary
FieldsFields inherited from class io.github.palexdev.materialfx.controls.MFXTextField
boundField, contextMenu, DEFAULT_TEXT_COLOR, floating, validatorFields 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_HEIGHTFields inherited from interface io.github.palexdev.materialfx.validation.Validated
INVALID_PSEUDO_CLASS -
Constructor Summary
ConstructorsConstructorDescriptionMFXPasswordField(String text) MFXPasswordField(String text, String promptText) MFXPasswordField(String text, String promptText, String floatingText) -
Method Summary
Modifier and TypeMethodDescriptionSpecifies if copying the password field text is allowed.Specifies if it's allowed to cut text from the password field.Specifies if it's allowed to paste text from the clipboard to the field.voidcopy()voidcut()voidprotected voidSets the default trailing icon for the password field.voidstatic List<CssMetaData<? extends Styleable,?>> List<CssMetaData<? extends Styleable,?>> Gets the value of the property hideCharacter.Specifies the character used to mask the text.booleanGets the value of the property allowCopy.booleanGets the value of the property allowCut.booleanGets the value of the property allowPaste.booleanGets the value of the property showPassword.voidnextWord()voidpaste()voidvoidvoidvoidvoidsetAllowCopy(boolean allowCopy) Sets the value of the property allowCopy.voidsetAllowCut(boolean allowCut) Sets the value of the property allowCut.voidsetAllowPaste(boolean allowPaste) Sets the value of the property allowPaste.protected voidSets the default behavior for the password field such:voidsetHideCharacter(String hideCharacter) Sets the value of the property hideCharacter.voidsetShowPassword(boolean showPassword) Sets the value of the property showPassword.Specifies if the text should be un-masked to show the password.Methods inherited from class io.github.palexdev.materialfx.controls.MFXTextField
allowEditProperty, animatedProperty, asLabel, asLabel, asLabel, asLabel, backward, borderGapProperty, caretVisibleProperty, clear, createDefaultSkin, delegateAnchorProperty, delegateCaretPositionProperty, delegateFocusedProperty, delegateGetAnchor, delegateGetCaretPosition, delegateGetSelectedText, delegateGetSelection, delegateGetTextFormatter, delegateIsFocused, delegateIsRedoable, delegateIsUndoable, delegateRedoableProperty, delegateSelectedTextProperty, delegateSelectionProperty, delegateSetTextFormatter, delegateTextFormatterProperty, delegateUndoableProperty, deselect, end, extendSelection, floatingProperty, floatingTextGapProperty, floatingTextProperty, floatModeProperty, forward, getBorderGap, getCaretVisible, getFloatingText, getFloatingTextGap, getFloatMode, getGraphicTextGap, getLeadingIcon, getMeasureUnit, getMeasureUnitGap, getMFXContextMenu, getTextFill, getTextLimit, getTrailingIcon, getValidator, graphicTextGapProperty, home, isAllowEdit, isAnimated, isFloating, isSelectable, leadingIconProperty, measureUnitGapProperty, measureUnitProperty, positionCaret, replaceSelection, scaleOnAbove, scaleOnAboveProperty, selectableProperty, selectAll, selectBackward, selectEnd, selectForward, selectHome, selectPositionCaret, selectRange, setAllowEdit, setAnimated, setBorderGap, setCaretVisible, setFloatingText, setFloatingTextGap, setFloatMode, setGraphicTextGap, setLeadingIcon, setMeasureUnit, setMeasureUnitGap, setScaleOnAbove, setSelectable, setTextFill, setTextLimit, setTrailingIcon, textFillProperty, textLimitProperty, trailingIconPropertyMethods 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, cancelEdit, caretPositionProperty, commitValue, deleteNextChar, deletePreviousChar, deleteText, deleteText, editableProperty, executeAccessibleAction, fontProperty, getAnchor, getCaretPosition, getContent, getFont, getLength, getPromptText, getSelectedText, getSelection, getText, getText, getTextFormatter, insertText, isEditable, isRedoable, isUndoable, lengthProperty, promptTextProperty, queryAccessibleAttribute, redo, redoableProperty, replaceText, replaceText, selectedTextProperty, selectionProperty, 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, 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, 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, visiblePropertyMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.github.palexdev.materialfx.controls.base.MFXMenuControl
isContextMenuDisabled, setContextMenuDisabledMethods inherited from interface javafx.css.Styleable
getStyleableNodeMethods inherited from interface io.github.palexdev.materialfx.validation.Validated
isValid, updateInvalid, validate
-
Property Details
-
allowCopy
Specifies if copying the password field text is allowed.- See Also:
-
allowCut
Specifies if it's allowed to cut text from the password field.- See Also:
-
allowPaste
Specifies if it's allowed to paste text from the clipboard to the field.- See Also:
-
showPassword
Specifies if the text should be un-masked to show the password.- See Also:
-
hideCharacter
Specifies the character used to mask the text.- See Also:
-
-
Field Details
-
BULLET
- See Also:
-
MASKED_PSEUDO_CLASS
-
-
Constructor Details
-
MFXPasswordField
public MFXPasswordField() -
MFXPasswordField
-
MFXPasswordField
-
MFXPasswordField
-
-
Method Details
-
setBehavior
protected void setBehavior()Sets the default behavior for the password field such:- Avoid worlds selection and only allowing selectAll()
- Managing the ":masked" PseudoClass
-
defaultTrailingIcon
protected void defaultTrailingIcon()Sets the default trailing icon for the password field.An eye to show/hide the password.
-
defaultContextMenu
public void defaultContextMenu()- Overrides:
defaultContextMenuin classMFXTextField
-
copy
public void copy()- Overrides:
copyin classMFXTextField
-
cut
public void cut()- Overrides:
cutin classMFXTextField
-
paste
public void paste()- Overrides:
pastein classMFXTextField
-
previousWord
public void previousWord()- Overrides:
previousWordin classMFXTextField
-
nextWord
public void nextWord()- Overrides:
nextWordin classMFXTextField
-
endOfNextWord
public void endOfNextWord()- Overrides:
endOfNextWordin classMFXTextField
-
selectPreviousWord
public void selectPreviousWord()- Overrides:
selectPreviousWordin classMFXTextField
-
selectNextWord
public void selectNextWord()- Overrides:
selectNextWordin classMFXTextField
-
selectEndOfNextWord
public void selectEndOfNextWord()- Overrides:
selectEndOfNextWordin classMFXTextField
-
getUserAgentStylesheet
- Overrides:
getUserAgentStylesheetin classMFXTextField
-
isAllowCopy
public boolean isAllowCopy()Gets the value of the property allowCopy.- Property description:
- Specifies if copying the password field text is allowed.
-
allowCopyProperty
Specifies if copying the password field text is allowed.- See Also:
-
setAllowCopy
public void setAllowCopy(boolean allowCopy) Sets the value of the property allowCopy.- Property description:
- Specifies if copying the password field text is allowed.
-
isAllowCut
public boolean isAllowCut()Gets the value of the property allowCut.- Property description:
- Specifies if it's allowed to cut text from the password field.
-
allowCutProperty
Specifies if it's allowed to cut text from the password field.- See Also:
-
setAllowCut
public void setAllowCut(boolean allowCut) Sets the value of the property allowCut.- Property description:
- Specifies if it's allowed to cut text from the password field.
-
isAllowPaste
public boolean isAllowPaste()Gets the value of the property allowPaste.- Property description:
- Specifies if it's allowed to paste text from the clipboard to the field.
-
allowPasteProperty
Specifies if it's allowed to paste text from the clipboard to the field.- See Also:
-
setAllowPaste
public void setAllowPaste(boolean allowPaste) Sets the value of the property allowPaste.- Property description:
- Specifies if it's allowed to paste text from the clipboard to the field.
-
isShowPassword
public boolean isShowPassword()Gets the value of the property showPassword.- Property description:
- Specifies if the text should be un-masked to show the password.
-
showPasswordProperty
Specifies if the text should be un-masked to show the password.- See Also:
-
setShowPassword
public void setShowPassword(boolean showPassword) Sets the value of the property showPassword.- Property description:
- Specifies if the text should be un-masked to show the password.
-
getHideCharacter
Gets the value of the property hideCharacter.- Property description:
- Specifies the character used to mask the text.
-
hideCharacterProperty
Specifies the character used to mask the text.- See Also:
-
setHideCharacter
Sets the value of the property hideCharacter.- Property description:
- Specifies the character used to mask the text.
-
getClassCssMetaData
-
getControlCssMetaData
- Overrides:
getControlCssMetaDatain classMFXTextField
-