Top Description Fields Constructors Methods
javafx.scene.control.skin

public Class TextFieldSkin

extends TextInputControlSkin<TextField>
Class Inheritance
Imports
java.util.List, javafx.beans.binding.BooleanBinding, .DoubleBinding, .ObjectBinding, .StringBinding, javafx.beans.property.DoubleProperty, .SimpleDoubleProperty, javafx.beans.value.ObservableBooleanValue, .ObservableDoubleValue, javafx.event.EventHandler, javafx.geometry.Bounds, .HPos, .NodeOrientation, .Point2D, .Rectangle2D, javafx.scene.AccessibleAttribute, .Group, .Node, javafx.scene.control.Control, .IndexRange, .PasswordField, .TextField, javafx.scene.input.MouseEvent, javafx.scene.layout.Pane, javafx.scene.paint.Color, .Paint, javafx.scene.shape.Path, .PathElement, .Rectangle, javafx.scene.text.HitInfo, .Text, com.sun.javafx.scene.control.behavior.PasswordFieldBehavior, .TextFieldBehavior, .TextInputControlBehavior, com.sun.javafx.scene.shape.TextHelper

Default skin implementation for the TextField control.
Since
9
See Also
TextField

Field Summary

Modifier and TypeField and Description
private final TextFieldBehavior
pack-priv static final char
private double
private Path
private Rectangle
clip

The clip, applied to the textGroup.

private Group
private double
private double
private Text
promptNode

The node used for showing the prompt text.

private Path
selectionHighlightPath

A path, provided by the textNode, which represents the area which is selected.

private Pane
textGroup

This group contains the text, caret, and selection rectangle.

private Text
textNode

The node actually displaying the text.

private ObservableDoubleValue
textRight

Right edge of the text region sans padding

private DoubleProperty
private ObservableBooleanValue
Inherited from javafx.scene.control.skin.TextInputControlSkin:
caretHandlecaretPathfontMetricsselectionHandle1selectionHandle2SHOW_HANDLES

Constructor Summary

AccessConstructor and Description
public
TextFieldSkin(final TextField
The control that this skin should be installed onto.
control
)

Creates a new TextFieldSkin instance, installing the necessary child nodes into the Control children list, as well as the necessary input mappings for handling key, mouse, etc events.

Method Summary

Modifier and TypeMethod and Description
protected void
addHighlight(List<? extends Node> nodes, int start)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.addHighlight.

Adds highlight for composed text from Input Method.

public double
computeBaselineOffset(double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeBaselineOffset.

Calculates the baseline offset based on the first managed child.

protected double
computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMaxHeight.

Computes the maximum allowable height of the Skin, based on the provided width.

protected double
computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMinHeight.

Computes the minimum allowable height of the Skin, based on the provided width.

protected double
computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computePrefHeight.

Calculates the preferred height of this SkinBase.

protected double
computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computePrefWidth.

Calculates the preferred width of this SkinBase.

private void
public void
deleteChar(boolean
whether to delete the preceding character.
previous
)

Deletes the character that follows or precedes the current caret position from the text if there is no selection, or deletes the selection if there is one.

public void
dispose()

Overrides javafx.scene.control.skin.TextInputControlSkin.dispose.

Implements javafx.scene.control.Skin.dispose.

Called when a previously installed skin is about to be removed from its associated control.

pack-priv TextInputControlBehavior<T extends TextInputControl>
public Rectangle2D
getCharacterBounds(int index)

Overrides javafx.scene.control.skin.TextInputControlSkin.getCharacterBounds.

Returns the bounds of the character at a given index.

private HPos
public HitInfo

Returns:

a HitInfo object describing the index and forward bias.
getIndex
(double
the x coordinate of the point.
x
,
double
the y coordinate of the point.
y
)

Performs a hit test, mapping point to index in the content.

public Point2D
getMenuPosition()

Overrides javafx.scene.control.skin.TextInputControlSkin.getMenuPosition.

Returns the position to be used for a context menu, based on the location of the caret handle or selection handles.

pack-priv Text
protected PathElement[]
getRangeShape(int start, int end)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.getRangeShape.

Gets the path elements describing the bounding rectangles for the given range of text.

pack-priv Text
pack-priv double
protected PathElement[]
getUnderlineShape(int start, int end)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.getUnderlineShape.

Gets the path elements describing the shape of the underline for the given range.

private final HitInfo
protected void
layoutChildren(final double x, final double y, final double w, final double h)

Overrides javafx.scene.control.SkinBase.layoutChildren.

Called during the layout pass of the scenegraph.

protected String
maskText(String txt)

Overrides javafx.scene.control.skin.TextInputControlSkin.maskText.

This method may be overridden by subclasses to replace the displayed characters without affecting the actual text content.

public void
moveCaret(TextInputControlSkin.TextUnit unit, TextInputControlSkin.Direction dir, boolean select)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.moveCaret.

Moves the caret by one of the given text unit, in the given direction.

private void
nextCharacterVisually(boolean moveRight)

public void
positionCaret(HitInfo
the new position and forward bias of the caret.
hit
,
boolean
whether to extend selection to the new position.
select
)

Moves the caret to the specified position.

private void
positionCaret(int pos, boolean leading, boolean select)

protected Object
queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.control.SkinBase.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

protected void
removeHighlight(List<? extends Node> nodes)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.removeHighlight.

Removes highlight for composed text from Input Method.

public void
replaceText(int
The starting index in the range, inclusive. This must be >= 0 and < the end.
start
,
int
The ending index in the range, exclusive. This is one-past the last character to delete (consistent with the String manipulation methods). This must be > the start, and <= the length of the text.
end
,
String
The text that is to replace the range. This must not be null.
txt
)

Replaces a range of characters with the given text.

private void
scrollAfterDelete(double textMaxXOld, double caretMaxXOld)

private void
private void
private void
private void
updateTextPos()

Updates the textTranslateX value for the Text node position.

Inherited from javafx.scene.control.skin.TextInputControlSkin:
caretVisiblePropertyexecuteAccessibleActionforwardBiasPropertygetClassCssMetaDatagetCssMetaDatagetHighlightFillgetHighlightTextFillgetInsertionPointgetPromptTextFillgetTextFillhandleInputMethodEventhighlightFillPropertyhighlightTextFillPropertyinstallinvalidateMetricsisCaretBlinkingisForwardBiasisRTLpromptTextFillPropertyscrollCharacterToVisiblesetCaretAnimatingsetForwardBiassetHighlightFillsetHighlightTextFillsetPromptTextFillsetTextFilltextFillPropertyupdateHighlightFillupdateHighlightTextFillupdateTextFill

Field Detail

behaviorback to summary
private final TextFieldBehavior behavior
BULLETback to summary
pack-priv static final char BULLET
caretWidthback to summary
private double caretWidth
characterBoundingPathback to summary
private Path characterBoundingPath
clipback to summary
private Rectangle clip

The clip, applied to the textGroup. This makes sure that any text / selection wandering off the text box is clipped

handleGroupback to summary
private Group handleGroup
pressXback to summary
private double pressX
pressYback to summary
private double pressY
promptNodeback to summary
private Text promptNode

The node used for showing the prompt text.

selectionHighlightPathback to summary
private Path selectionHighlightPath

A path, provided by the textNode, which represents the area which is selected. The path elements which make up the selection must be updated whenever the selection changes. We don't need to keep track of text changes because those will force the selection to be updated.

textGroupback to summary
private Pane textGroup

This group contains the text, caret, and selection rectangle. It is clipped. The textNode, selectionHighlightPath, and caret are each translated individually when horizontal translation is needed to keep the caretPosition visible.

textNodeback to summary
private Text textNode

The node actually displaying the text. Note that it has the ability to render both the normal fill as well as the highlight fill, to perform hit testing, fetching of the selection highlight, and other such duties.

textRightback to summary
private ObservableDoubleValue textRight

Right edge of the text region sans padding

textTranslateXback to summary
private DoubleProperty textTranslateX
usePromptTextback to summary
private ObservableBooleanValue usePromptText

Constructor Detail

TextFieldSkinback to summary
public TextFieldSkin(final TextField control)

Creates a new TextFieldSkin instance, installing the necessary child nodes into the Control children list, as well as the necessary input mappings for handling key, mouse, etc events.

Parameters
control:TextField

The control that this skin should be installed onto.

Method Detail

addHighlightback to summary
protected void addHighlight(List<? extends Node> nodes, int start)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.addHighlight.

Doc from javafx.scene.control.skin.TextInputControlSkin.addHighlight.

Adds highlight for composed text from Input Method.

Annotations
@Override
computeBaselineOffsetback to summary
public double computeBaselineOffset(double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeBaselineOffset.

Doc from javafx.scene.control.SkinBase.computeBaselineOffset.

Calculates the baseline offset based on the first managed child. If there is no such child, returns Node#getBaselineOffset().

Annotations
@Override
computeMaxHeightback to summary
protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMaxHeight.

Doc from javafx.scene.control.SkinBase.computeMaxHeight.

Computes the maximum allowable height of the Skin, based on the provided width.

Annotations
@Override
computeMinHeightback to summary
protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computeMinHeight.

Doc from javafx.scene.control.SkinBase.computeMinHeight.

Computes the minimum allowable height of the Skin, based on the provided width.

Annotations
@Override
computePrefHeightback to summary
protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computePrefHeight.

Doc from javafx.scene.control.SkinBase.computePrefHeight.

Calculates the preferred height of this SkinBase. The default implementation calculates this height as the height of the area occupied by its managed children when they are positioned at their current positions at their preferred heights.

Annotations
@Override
computePrefWidthback to summary
protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset)

Overrides javafx.scene.control.SkinBase.computePrefWidth.

Doc from javafx.scene.control.SkinBase.computePrefWidth.

Calculates the preferred width of this SkinBase. The default implementation calculates this width as the width of the area occupied by its managed children when they are positioned at their current positions at their preferred widths.

Annotations
@Override
createPromptNodeback to summary
private void createPromptNode()
deleteCharback to summary
public void deleteChar(boolean previous)

Deletes the character that follows or precedes the current caret position from the text if there is no selection, or deletes the selection if there is one. Call this implementation from behavior classes instead of the one provided on TextInputControl to ensure that the text scrolls as needed.

Parameters
previous:boolean

whether to delete the preceding character.

disposeback to summary
public void dispose()

Overrides javafx.scene.control.skin.TextInputControlSkin.dispose.

Implements javafx.scene.control.Skin.dispose.

Doc from javafx.scene.control.SkinBase.dispose.

Called when a previously installed skin is about to be removed from its associated control. This allows the skin to do clean up, like removing listeners and bindings, and undo any changes to the control's properties. After this method completes, getSkinnable() and getNode() should return null.

Calling dispose() more than once has no effect.

Annotations
@Override
getBehaviorback to summary
pack-priv TextInputControlBehavior<T extends TextInputControl> getBehavior()

Overrides javafx.scene.control.skin.TextInputControlSkin.getBehavior.

Annotations
@Override
getCharacterBoundsback to summary
public Rectangle2D getCharacterBounds(int index)

Overrides javafx.scene.control.skin.TextInputControlSkin.getCharacterBounds.

Doc from javafx.scene.control.skin.TextInputControlSkin.getCharacterBounds.

Returns the bounds of the character at a given index.

Annotations
@Override
getHAlignmentback to summary
private HPos getHAlignment()
getIndexback to summary
public HitInfo getIndex(double x, double y)

Performs a hit test, mapping point to index in the content.

Parameters
x:double

the x coordinate of the point.

y:double

the y coordinate of the point.

Returns:HitInfo

a HitInfo object describing the index and forward bias.

getMenuPositionback to summary
public Point2D getMenuPosition()

Overrides javafx.scene.control.skin.TextInputControlSkin.getMenuPosition.

Doc from javafx.scene.control.skin.TextInputControlSkin.getMenuPosition.

Returns the position to be used for a context menu, based on the location of the caret handle or selection handles. This is supported only on touch displays and does not use the location of the mouse.

Annotations
@Override
getPromptNodeback to summary
pack-priv Text getPromptNode()
getRangeShapeback to summary
protected PathElement[] getRangeShape(int start, int end)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.getRangeShape.

Doc from javafx.scene.control.skin.TextInputControlSkin.getRangeShape.

Gets the path elements describing the bounding rectangles for the given range of text.

Annotations
@Override
getTextNodeback to summary
pack-priv Text getTextNode()
getTextTranslateXback to summary
pack-priv double getTextTranslateX()
getUnderlineShapeback to summary
protected PathElement[] getUnderlineShape(int start, int end)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.getUnderlineShape.

Doc from javafx.scene.control.skin.TextInputControlSkin.getUnderlineShape.

Gets the path elements describing the shape of the underline for the given range.

Annotations
@Override
hitTestback to summary
private final HitInfo hitTest(Point2D p)
layoutChildrenback to summary
protected void layoutChildren(final double x, final double y, final double w, final double h)

Overrides javafx.scene.control.SkinBase.layoutChildren.

Doc from javafx.scene.control.SkinBase.layoutChildren.

Called during the layout pass of the scenegraph.

Annotations
@Override
maskTextback to summary
protected String maskText(String txt)

Overrides javafx.scene.control.skin.TextInputControlSkin.maskText.

Doc from javafx.scene.control.skin.TextInputControlSkin.maskText.

This method may be overridden by subclasses to replace the displayed characters without affecting the actual text content. This is used to display bullet characters in PasswordField.

Annotations
@Override
moveCaretback to summary
public void moveCaret(TextInputControlSkin.TextUnit unit, TextInputControlSkin.Direction dir, boolean select)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.moveCaret.

Doc from javafx.scene.control.skin.TextInputControlSkin.moveCaret.

Moves the caret by one of the given text unit, in the given direction. Note that only certain combinations are valid, depending on the implementing subclass.

Annotations
@Override
nextCharacterVisuallyback to summary
private void nextCharacterVisually(boolean moveRight)
positionCaretback to summary
public void positionCaret(HitInfo hit, boolean select)

Moves the caret to the specified position.

Parameters
hit:HitInfo

the new position and forward bias of the caret.

select:boolean

whether to extend selection to the new position.

positionCaretback to summary
private void positionCaret(int pos, boolean leading, boolean select)
queryAccessibleAttributeback to summary
protected Object queryAccessibleAttribute(AccessibleAttribute attribute, Object... parameters)

Overrides javafx.scene.control.SkinBase.queryAccessibleAttribute.

Doc from javafx.scene.control.SkinBase.queryAccessibleAttribute.

This method is called by the assistive technology to request the value for an attribute.

This method is commonly overridden by subclasses to implement attributes that are required for a specific role.
If a particular attribute is not handled, the superclass implementation must be called.

Annotations
@Override
removeHighlightback to summary
protected void removeHighlight(List<? extends Node> nodes)

Implements abstract javafx.scene.control.skin.TextInputControlSkin.removeHighlight.

Doc from javafx.scene.control.skin.TextInputControlSkin.removeHighlight.

Removes highlight for composed text from Input Method.

Annotations
@Override
replaceTextback to summary
public void replaceText(int start, int end, String txt)

Replaces a range of characters with the given text. Call this implementation from behavior classes instead of the one provided on TextInputControl to ensure that the text scrolls as needed.

Parameters
start:int

The starting index in the range, inclusive. This must be >= 0 and < the end.

end:int

The ending index in the range, exclusive. This is one-past the last character to delete (consistent with the String manipulation methods). This must be > the start, and <= the length of the text.

txt:String

The text that is to replace the range. This must not be null.

See Also
TextField#replaceText(int, int, String)
scrollAfterDeleteback to summary
private void scrollAfterDelete(double textMaxXOld, double caretMaxXOld)
updateCaretOffback to summary
private void updateCaretOff()
updateSelectionback to summary
private void updateSelection()
updateTextNodeCaretPosback to summary
private void updateTextNodeCaretPos(int pos)
updateTextPosback to summary
private void updateTextPos()

Updates the textTranslateX value for the Text node position. This is done for general layout, but care is taken to avoid resetting the position when there's a need to scroll the text due to caret movement, or when editing text that overflows on either side.