public class Text
extends Shape
Text
class defines a node that displays a text.
Paragraphs are separated by '\n'
and the text is wrapped on
paragraph boundaries.
import javafx.scene.text.*; Text t = new Text(10, 50, "This is a test"); t.setFont(new Font(20));
import javafx.scene.text.*; Text t = new Text(); text.setFont(new Font(20)); text.setText("First row\nSecond row");
import javafx.scene.text.*; Text t = new Text(); text.setFont(new Font(20)); text.setWrappingWidth(200); text.setTextAlignment(TextAlignment.JUSTIFY) text.setText("The quick brown fox jumps over the lazy dog");
Type | Property and Description |
---|---|
ReadOnlyDoubleProperty |
baselineOffset
The 'alphabetic' (or roman) baseline offset from the Text node's
layoutBounds.minY location.
|
<any> |
boundsType
Determines how the bounds of the text node are calculated.
|
BooleanProperty |
caretBias |
IntegerProperty |
caretPosition |
<any> |
caretShape |
<any> |
font
Defines the font of text.
|
<any> |
fontSmoothingType
Specifies a requested font smoothing type : gray or LCD.
|
DoubleProperty |
lineSpacing
Defines the vertical space in pixel between lines.
|
IntegerProperty |
selectionEnd |
<any> |
selectionFill
The fill color of selected text.
|
<any> |
selectionShape |
IntegerProperty |
selectionStart |
BooleanProperty |
strikethrough
Defines if each line of text should have a line through it.
|
<any> |
textAlignment
Defines horizontal text alignment in the bounding box.
|
<any> |
textOrigin
Defines the origin of text coordinate system in local coordinates.
|
StringProperty |
text
Defines text string that is to be displayed.
|
BooleanProperty |
underline
Defines if each line of text should have a line below it.
|
DoubleProperty |
wrappingWidth
Defines a width constraint for the text in user space coordinates,
e.g.
|
DoubleProperty |
x
Defines the X coordinate of text origin.
|
DoubleProperty |
y
Defines the Y coordinate of text origin.
|
Modifier and Type | Class and Description |
---|---|
private static class |
Text.StyleableProperties
*
Stylesheet Handling *
*
|
private class |
Text.TextAttribute |
Modifier and Type | Field and Description |
---|---|
private Text.TextAttribute |
attributes
*
Seldom Used Properties *
*
|
private <any> |
boundsType
Determines how the bounds of the text node are calculated.
|
private static TextBoundsType |
DEFAULT_BOUNDS_TYPE |
private static boolean |
DEFAULT_CARET_BIAS |
private static int |
DEFAULT_CARET_POSITION |
private static double |
DEFAULT_LINE_SPACING |
private static int |
DEFAULT_SELECTION_END |
private static Color |
DEFAULT_SELECTION_FILL |
private static int |
DEFAULT_SELECTION_START |
private static boolean |
DEFAULT_STRIKETHROUGH |
private static TextAlignment |
DEFAULT_TEXT_ALIGNMENT |
private static VPos |
DEFAULT_TEXT_ORIGIN |
private static boolean |
DEFAULT_UNDERLINE |
private static PathElement[] |
EMPTY_PATH_ELEMENT_ARRAY |
private <any> |
font
Defines the font of text.
|
private <any> |
fontSmoothingType
Specifies a requested font smoothing type : gray or LCD.
|
private boolean |
isSpan |
private TextLayout |
layout |
private BaseBounds |
spanBounds |
private boolean |
spanBoundsInvalid |
private StringProperty |
text
Defines text string that is to be displayed.
|
private GlyphList[] |
textRuns |
private TextSpan |
textSpan |
private DoubleProperty |
wrappingWidth
Defines a width constraint for the text in user space coordinates,
e.g.
|
private DoubleProperty |
x
Defines the X coordinate of text origin.
|
private DoubleProperty |
y
Defines the Y coordinate of text origin.
|
Constructor and Description |
---|
Text()
Creates an empty instance of Text.
|
Text(double x,
double y,
java.lang.String text)
Creates an instance of Text on the given coordinates containing the
given string.
|
Text(java.lang.String text)
Creates an instance of Text containing the given string.
|
Modifier and Type | Method and Description |
---|---|
ReadOnlyDoubleProperty |
baselineOffsetProperty()
The 'alphabetic' (or roman) baseline offset from the Text node's
layoutBounds.minY location.
|
<any> |
boundsTypeProperty()
Determines how the bounds of the text node are calculated.
|
BooleanProperty |
caretBiasProperty() |
IntegerProperty |
caretPositionProperty() |
PathElement[] |
caretShape(int charIndex,
boolean caretBias)
Returns shape for the caret at given index and bias.
|
<any> |
caretShapeProperty() |
private void |
checkOrientation() |
private void |
checkSpan() |
private boolean |
doComputeContains(double localX,
double localY) |
private BaseBounds |
doComputeGeomBounds(BaseBounds bounds,
BaseTransform tx) |
private Bounds |
doComputeLayoutBounds() |
private com.sun.javafx.geom.Shape |
doConfigShape() |
private NGNode |
doCreatePeer() |
private void |
doGeomChanged() |
private void |
doUpdatePeer() |
<any> |
fontProperty()
Defines the font of text.
|
<any> |
fontSmoothingTypeProperty()
Specifies a requested font smoothing type : gray or LCD.
|
double |
getBaselineOffset()
Gets the value of the property baselineOffset.
|
TextBoundsType |
getBoundsType()
Gets the value of the property boundsType.
|
int |
getCaretPosition()
Gets the value of the property caretPosition.
|
PathElement[] |
getCaretShape()
Shape of caret in local coordinates.
|
static java.util.List<<any>> |
getClassCssMetaData() |
java.util.List<<any>> |
getCssMetaData() |
Font |
getFont()
Gets the value of the property font.
|
private java.lang.Object |
getFontInternal()
Internally used safe version of getFont which never returns null.
|
FontSmoothingType |
getFontSmoothingType()
Gets the value of the property fontSmoothingType.
|
double |
getLineSpacing()
Gets the value of the property lineSpacing.
|
private BaseBounds |
getLogicalBounds() |
private PathElement[] |
getRange(int start,
int end,
int type) |
private GlyphList[] |
getRuns() |
int |
getSelectionEnd()
Gets the value of the property selectionEnd.
|
Paint |
getSelectionFill()
Gets the value of the property selectionFill.
|
PathElement[] |
getSelectionShape()
Shape of selection in local coordinates.
|
int |
getSelectionStart()
Gets the value of the property selectionStart.
|
private com.sun.javafx.geom.Shape |
getShape() |
(package private) BaseBounds |
getSpanBounds() |
java.lang.String |
getText()
Gets the value of the property text.
|
TextAlignment |
getTextAlignment()
Gets the value of the property textAlignment.
|
private Text.TextAttribute |
getTextAttribute() |
private java.lang.String |
getTextInternal() |
private TextLayout |
getTextLayout() |
VPos |
getTextOrigin()
Gets the value of the property textOrigin.
|
(package private) TextSpan |
getTextSpan() |
private BaseBounds |
getVisualBounds() |
double |
getWrappingWidth()
Gets the value of the property wrappingWidth.
|
double |
getX()
Gets the value of the property x.
|
double |
getY()
Gets the value of the property y.
|
private float |
getYAdjustment(BaseBounds bounds) |
private float |
getYRendering() |
HitInfo |
hitTest(Point2D point)
Maps local point to index in the content.
|
boolean |
isCaretBias()
Gets the value of the property caretBias.
|
private boolean |
isSpan() |
boolean |
isStrikethrough()
Gets the value of the property strikethrough.
|
boolean |
isUnderline()
Gets the value of the property underline.
|
(package private) void |
layoutSpan(GlyphList[] runs) |
DoubleProperty |
lineSpacingProperty()
Defines the vertical space in pixel between lines.
|
private void |
needsFullTextLayout() |
private void |
needsTextLayout() |
java.lang.Object |
queryAccessibleAttribute(AccessibleAttribute attribute,
java.lang.Object... parameters) |
PathElement[] |
rangeShape(int start,
int end)
Returns shape for the range of the text in local coordinates.
|
IntegerProperty |
selectionEndProperty() |
<any> |
selectionFillProperty()
The fill color of selected text.
|
<any> |
selectionShapeProperty() |
IntegerProperty |
selectionStartProperty() |
void |
setBoundsType(TextBoundsType value)
Sets the value of the property boundsType.
|
void |
setCaretBias(boolean value)
caret bias in the content.
|
void |
setCaretPosition(int value)
Caret index in the content.
|
void |
setFont(Font value)
Sets the value of the property font.
|
void |
setFontSmoothingType(FontSmoothingType value)
Sets the value of the property fontSmoothingType.
|
void |
setLineSpacing(double spacing)
Sets the value of the property lineSpacing.
|
void |
setSelectionEnd(int value)
Selection end index in the content.
|
void |
setSelectionFill(Paint paint)
Sets the value of the property selectionFill.
|
void |
setSelectionStart(int value)
Selection start index in the content.
|
void |
setStrikethrough(boolean value)
Sets the value of the property strikethrough.
|
void |
setText(java.lang.String value)
Sets the value of the property text.
|
void |
setTextAlignment(TextAlignment value)
Sets the value of the property textAlignment.
|
void |
setTextOrigin(VPos value)
Sets the value of the property textOrigin.
|
void |
setUnderline(boolean value)
Sets the value of the property underline.
|
void |
setWrappingWidth(double value)
Sets the value of the property wrappingWidth.
|
void |
setX(double value)
Sets the value of the property x.
|
void |
setY(double value)
Sets the value of the property y.
|
BooleanProperty |
strikethroughProperty()
Defines if each line of text should have a line through it.
|
<any> |
textAlignmentProperty()
Defines horizontal text alignment in the bounding box.
|
<any> |
textOriginProperty()
Defines the origin of text coordinate system in local coordinates.
|
StringProperty |
textProperty()
Defines text string that is to be displayed.
|
java.lang.String |
toString()
Returns a string representation of this
Text object. |
BooleanProperty |
underlineProperty()
Defines if each line of text should have a line below it.
|
PathElement[] |
underlineShape(int start,
int end)
Returns shape for the underline in local coordinates.
|
private void |
updatePGText() |
boolean |
usesMirroring() |
DoubleProperty |
wrappingWidthProperty()
Defines a width constraint for the text in user space coordinates,
e.g.
|
DoubleProperty |
xProperty()
Defines the X coordinate of text origin.
|
DoubleProperty |
yProperty()
Defines the Y coordinate of text origin.
|
public final StringProperty textProperty
getText()
,
setText(String)
public final DoubleProperty xProperty
getX()
,
setX(double)
public final DoubleProperty yProperty
getY()
,
setY(double)
public final <any> fontProperty
getFont()
,
setFont(Font)
public final <any> textOriginProperty
VPos.BASELINE
and
VPos.TOP
define the origin of the top row while
VPos.BOTTOM
defines the origin of the bottom row.getTextOrigin()
,
setTextOrigin(VPos)
public final <any> boundsTypeProperty
TextBoundsType
for more information.getBoundsType()
,
setBoundsType(TextBoundsType)
public final DoubleProperty wrappingWidthProperty
> 0
text will be line wrapped as needed
to satisfy this constraint.getWrappingWidth()
,
setWrappingWidth(double)
public final BooleanProperty underlineProperty
isUnderline()
,
setUnderline(boolean)
public final BooleanProperty strikethroughProperty
isStrikethrough()
,
setStrikethrough(boolean)
public final <any> textAlignmentProperty
public final DoubleProperty lineSpacingProperty
getLineSpacing()
,
setLineSpacing(double)
public final ReadOnlyDoubleProperty baselineOffsetProperty
getBaselineOffset()
public final <any> fontSmoothingTypeProperty
getFontSmoothingType()
,
setFontSmoothingType(FontSmoothingType)
public final <any> selectionShapeProperty
getSelectionShape()
public final IntegerProperty selectionStartProperty
getSelectionStart()
,
setSelectionStart(int)
public final IntegerProperty selectionEndProperty
getSelectionEnd()
,
setSelectionEnd(int)
public final <any> selectionFillProperty
getSelectionFill()
,
setSelectionFill(Paint)
public final <any> caretShapeProperty
getCaretShape()
public final IntegerProperty caretPositionProperty
getCaretPosition()
,
setCaretPosition(int)
public final BooleanProperty caretBiasProperty
isCaretBias()
,
setCaretBias(boolean)
private TextLayout layout
private static final PathElement[] EMPTY_PATH_ELEMENT_ARRAY
private boolean isSpan
private TextSpan textSpan
private GlyphList[] textRuns
private BaseBounds spanBounds
private boolean spanBoundsInvalid
private StringProperty text
private DoubleProperty x
private DoubleProperty y
private <any> font
private <any> boundsType
TextBoundsType
for more information.private DoubleProperty wrappingWidth
> 0
text will be line wrapped as needed
to satisfy this constraint.private <any> fontSmoothingType
private Text.TextAttribute attributes
private static final VPos DEFAULT_TEXT_ORIGIN
private static final TextBoundsType DEFAULT_BOUNDS_TYPE
private static final boolean DEFAULT_UNDERLINE
private static final boolean DEFAULT_STRIKETHROUGH
private static final TextAlignment DEFAULT_TEXT_ALIGNMENT
private static final double DEFAULT_LINE_SPACING
private static final int DEFAULT_CARET_POSITION
private static final int DEFAULT_SELECTION_START
private static final int DEFAULT_SELECTION_END
private static final Color DEFAULT_SELECTION_FILL
private static final boolean DEFAULT_CARET_BIAS
public Text()
public Text(java.lang.String text)
text
- text to be contained in the instancepublic Text(double x, double y, java.lang.String text)
x
- the horizontal position of the texty
- the vertical position of the texttext
- text to be contained in the instanceprivate NGNode doCreatePeer()
private boolean isSpan()
private void checkSpan()
private void checkOrientation()
public boolean usesMirroring()
private void needsFullTextLayout()
private void needsTextLayout()
TextSpan getTextSpan()
private TextLayout getTextLayout()
void layoutSpan(GlyphList[] runs)
BaseBounds getSpanBounds()
private GlyphList[] getRuns()
private com.sun.javafx.geom.Shape getShape()
private BaseBounds getVisualBounds()
private BaseBounds getLogicalBounds()
public final void setText(java.lang.String value)
public final java.lang.String getText()
private java.lang.String getTextInternal()
public final StringProperty textProperty()
getText()
,
setText(String)
public final void setX(double value)
public final double getX()
public final DoubleProperty xProperty()
getX()
,
setX(double)
public final void setY(double value)
public final double getY()
public final DoubleProperty yProperty()
getY()
,
setY(double)
public final void setFont(Font value)
public final Font getFont()
private java.lang.Object getFontInternal()
public final <any> fontProperty()
getFont()
,
setFont(Font)
public final void setTextOrigin(VPos value)
public final VPos getTextOrigin()
public final <any> textOriginProperty()
VPos.BASELINE
and
VPos.TOP
define the origin of the top row while
VPos.BOTTOM
defines the origin of the bottom row.getTextOrigin()
,
setTextOrigin(VPos)
public final void setBoundsType(TextBoundsType value)
public final TextBoundsType getBoundsType()
public final <any> boundsTypeProperty()
TextBoundsType
for more information.getBoundsType()
,
setBoundsType(TextBoundsType)
public final void setWrappingWidth(double value)
public final double getWrappingWidth()
public final DoubleProperty wrappingWidthProperty()
> 0
text will be line wrapped as needed
to satisfy this constraint.getWrappingWidth()
,
setWrappingWidth(double)
public final void setUnderline(boolean value)
public final boolean isUnderline()
public final BooleanProperty underlineProperty()
isUnderline()
,
setUnderline(boolean)
public final void setStrikethrough(boolean value)
public final boolean isStrikethrough()
public final BooleanProperty strikethroughProperty()
isStrikethrough()
,
setStrikethrough(boolean)
public final void setTextAlignment(TextAlignment value)
public final TextAlignment getTextAlignment()
public final <any> textAlignmentProperty()
public final void setLineSpacing(double spacing)
public final double getLineSpacing()
public final DoubleProperty lineSpacingProperty()
getLineSpacing()
,
setLineSpacing(double)
public final double getBaselineOffset()
public final ReadOnlyDoubleProperty baselineOffsetProperty()
getBaselineOffset()
public final void setFontSmoothingType(FontSmoothingType value)
public final FontSmoothingType getFontSmoothingType()
public final <any> fontSmoothingTypeProperty()
getFontSmoothingType()
,
setFontSmoothingType(FontSmoothingType)
private void doGeomChanged()
public final PathElement[] getSelectionShape()
public final <any> selectionShapeProperty()
getSelectionShape()
public final void setSelectionStart(int value)
-1
to unset selection.value
- the selection start indexpublic final int getSelectionStart()
public final IntegerProperty selectionStartProperty()
getSelectionStart()
,
setSelectionStart(int)
public final void setSelectionEnd(int value)
-1
to unset selection.value
- the selection end indexpublic final int getSelectionEnd()
public final IntegerProperty selectionEndProperty()
getSelectionEnd()
,
setSelectionEnd(int)
public final <any> selectionFillProperty()
getSelectionFill()
,
setSelectionFill(Paint)
public final void setSelectionFill(Paint paint)
public final Paint getSelectionFill()
public final PathElement[] getCaretShape()
public final <any> caretShapeProperty()
getCaretShape()
public final void setCaretPosition(int value)
-1
to unset caret.value
- the caret index in the contentpublic final int getCaretPosition()
public final IntegerProperty caretPositionProperty()
getCaretPosition()
,
setCaretPosition(int)
public final void setCaretBias(boolean value)
true
means a bias towards the leading character edge.
(true=leading/false=trailing)value
- the caret bias in the contentpublic final boolean isCaretBias()
public final BooleanProperty caretBiasProperty()
isCaretBias()
,
setCaretBias(boolean)
public final HitInfo hitTest(Point2D point)
point
- the specified point to be testedHitInfo
representing the character index foundprivate PathElement[] getRange(int start, int end, int type)
public final PathElement[] caretShape(int charIndex, boolean caretBias)
charIndex
- the character index for the caretcaretBias
- whether the caret is biased on the leading edge of the characterPathElement
which can be used to create a Shape
public final PathElement[] rangeShape(int start, int end)
start
- the beginning character index for the rangeend
- the end character index (non-inclusive) for the rangePathElement
which can be used to create a Shape
public final PathElement[] underlineShape(int start, int end)
start
- the beginning character index for the rangeend
- the end character index (non-inclusive) for the rangePathElement
which can be used to create a Shape
private float getYAdjustment(BaseBounds bounds)
private float getYRendering()
private Bounds doComputeLayoutBounds()
private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx)
private boolean doComputeContains(double localX, double localY)
private com.sun.javafx.geom.Shape doConfigShape()
public static java.util.List<<any>> getClassCssMetaData()
public java.util.List<<any>> getCssMetaData()
private void updatePGText()
private void doUpdatePeer()
private Text.TextAttribute getTextAttribute()
public java.lang.String toString()
Text
object.Text
object.public java.lang.Object queryAccessibleAttribute(AccessibleAttribute attribute, java.lang.Object... parameters)