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, trailingIcon
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, 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, validator
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
Fields 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.void
copy()
void
cut()
void
protected void
Sets the default trailing icon for the password field.void
static List<CssMetaData<? extends Styleable,
?>> List<CssMetaData<? extends Styleable,
?>> Gets the value of the property hideCharacter.Specifies the character used to mask the text.boolean
Gets the value of the property allowCopy.boolean
Gets the value of the property allowCut.boolean
Gets the value of the property allowPaste.boolean
Gets the value of the property showPassword.void
nextWord()
void
paste()
void
void
void
void
void
setAllowCopy
(boolean allowCopy) Sets the value of the property allowCopy.void
setAllowCut
(boolean allowCut) Sets the value of the property allowCut.void
setAllowPaste
(boolean allowPaste) Sets the value of the property allowPaste.protected void
Sets the default behavior for the password field such:void
setHideCharacter
(String hideCharacter) Sets the value of the property hideCharacter.void
setShowPassword
(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, trailingIconProperty
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, 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, 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, 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, visibleProperty
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface io.github.palexdev.materialfx.controls.base.MFXMenuControl
isContextMenuDisabled, setContextMenuDisabled
Methods inherited from interface javafx.css.Styleable
getStyleableNode
Methods 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:
defaultContextMenu
in classMFXTextField
-
copy
public void copy()- Overrides:
copy
in classMFXTextField
-
cut
public void cut()- Overrides:
cut
in classMFXTextField
-
paste
public void paste()- Overrides:
paste
in classMFXTextField
-
previousWord
public void previousWord()- Overrides:
previousWord
in classMFXTextField
-
nextWord
public void nextWord()- Overrides:
nextWord
in classMFXTextField
-
endOfNextWord
public void endOfNextWord()- Overrides:
endOfNextWord
in classMFXTextField
-
selectPreviousWord
public void selectPreviousWord()- Overrides:
selectPreviousWord
in classMFXTextField
-
selectNextWord
public void selectNextWord()- Overrides:
selectNextWord
in classMFXTextField
-
selectEndOfNextWord
public void selectEndOfNextWord()- Overrides:
selectEndOfNextWord
in classMFXTextField
-
getUserAgentStylesheet
- Overrides:
getUserAgentStylesheet
in 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:
getControlCssMetaData
in classMFXTextField
-