Class TextElement
- All Implemented Interfaces:
Serializable
<text> element.
The <text> element defines a graphics element consisting of text.
It's possible to apply a gradient, pattern, clipping path, mask, or filter
to text like any other SVG graphics element.
Write-Only vs Read-Write Methods
This class provides two variants for each attribute setter:
- Default methods (e.g.,
x(),y()) - Use an optimized write-only approach. Attribute values are NOT stored on the server and cannot be retrieved viagetAttribute(). - RW methods (e.g.,
xRW(),yRW()) - Use traditionalsetAttribute()which stores values on the server for later retrieval.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDominant baseline options for vertical alignment.static enumFont style options.static enumFont weight options.static enumText anchor options for horizontal alignment.static enumText decoration options.Nested classes/interfaces inherited from class SvgGraphicsElement
SvgGraphicsElement.LineCap, SvgGraphicsElement.LineJoinNested classes/interfaces inherited from class SvgElement
SvgElement.PreserveAspectRatio -
Constructor Summary
ConstructorsConstructorDescriptionTextElement(double x, double y, String text) Creates a text element at the specified position.TextElement(String text) Creates a text element with the given text content. -
Method Summary
Modifier and TypeMethodDescriptionadd(SvgElement... children) Adds child elements to this text element.dominantBaseline(TextElement.DominantBaseline baseline) Sets the dominant baseline (vertical alignment).Sets the dominant baseline (vertical alignment) (read-write).dx(double dx) Sets the horizontal shift from the previous text position.dxRW(double dx) Sets the horizontal shift from the previous text position (read-write).dy(double dy) Sets the vertical shift from the previous text position.dyRW(double dy) Sets the vertical shift from the previous text position (read-write).fontFamily(String fontFamily) Sets the font family.fontFamilyRW(String fontFamily) Sets the font family (read-write).fontSize(double size) Sets the font size.Sets the font size with a unit.fontSizeRW(double size) Sets the font size (read-write).fontSizeRW(String size) Sets the font size with a unit (read-write).fontStyle(TextElement.FontStyle style) Sets the font style.fontStyleRW(TextElement.FontStyle style) Sets the font style (read-write).fontWeight(TextElement.FontWeight weight) Sets the font weight.fontWeightRW(TextElement.FontWeight weight) Sets the font weight (read-write).letterSpacing(double spacing) Sets the letter spacing.letterSpacing(String spacing) Sets the letter spacing with a unit.letterSpacingRW(double spacing) Sets the letter spacing (read-write).letterSpacingRW(String spacing) Sets the letter spacing with a unit (read-write).position(double x, double y) Sets the position of the text.positionRW(double x, double y) Sets the position of the text (read-write).Sets the rotation for each character.Sets the rotation for each character (read-write).Sets the text content.textAnchor(TextElement.TextAnchor anchor) Sets the text anchor (horizontal alignment).textAnchorRW(TextElement.TextAnchor anchor) Sets the text anchor (horizontal alignment) (read-write).textDecoration(TextElement.TextDecoration decoration) Sets the text decoration.textDecorationRW(TextElement.TextDecoration decoration) Sets the text decoration (read-write).textLength(double length) Sets the total length of the text.textLengthRW(double length) Sets the total length of the text (read-write).wordSpacing(double spacing) Sets the word spacing.wordSpacingRW(double spacing) Sets the word spacing (read-write).x(double x) Sets the x coordinate of the text starting point.Sets the x coordinate with a unit.xRW(double x) Sets the x coordinate of the text starting point (read-write).Sets the x coordinate with a unit (read-write).y(double y) Sets the y coordinate of the text starting point.Sets the y coordinate with a unit.yRW(double y) Sets the y coordinate of the text starting point (read-write).Sets the y coordinate with a unit (read-write).Methods inherited from class SvgGraphicsElement
clearTransform, clipPath, clipPathRW, fill, fill, fill, fill, fill, fillOpacity, fillOpacityRW, fillRW, fillRW, fillRW, fillRW, fillRW, mask, maskRW, matrix, matrixRW, noFill, noFillRW, noStroke, noStrokeRW, opacity, opacityRW, rotate, rotate, rotateRW, rotateRW, scale, scale, scaleRW, scaleRW, skewX, skewXRW, skewY, skewYRW, stroke, stroke, stroke, stroke, stroke, strokeDasharray, strokeDasharray, strokeDasharrayRW, strokeDasharrayRW, strokeDashoffset, strokeDashoffsetRW, strokeLinecap, strokeLinecapRW, strokeLinejoin, strokeLinejoinRW, strokeMiterlimit, strokeMiterlimitRW, strokeOpacity, strokeOpacityRW, strokeRW, strokeRW, strokeRW, strokeRW, strokeRW, strokeWidth, strokeWidth, strokeWidthRW, strokeWidthRW, transform, transformRW, translate, translateRW, translateX, translateXRW, translateY, translateYRWMethods inherited from class SvgElement
emptySvgRoot, flushPendingAttributes, getOuterHTML, getPendingOrAttribute, getStyle, height, height, id, preserveAspectRatio, preserveAspectRatio, scheduleBeforeClientResponse, setAttribute, setWriteOnlyAttribute, size, size, viewBox, width, widthMethods inherited from class com.vaadin.flow.dom.Element
addAttachListener, addDetachListener, addEventListener, addPropertyChangeListener, addPropertyChangeListener, as, attachShadow, bindAttribute, bindProperty, bindText, callJsFunction, callJsFunction, createText, executeJs, executeJs, get, get, getAttribute, getAttributeNames, getChild, getChildCount, getChildren, getClassList, getComponent, getParent, getProperty, getProperty, getProperty, getProperty, getProperty, getPropertyBean, getPropertyBean, getPropertyNames, getPropertyRaw, getSelf, getShadowRoot, getTag, getText, getTextRecursively, getThemeList, hasAttribute, hasProperty, isEnabled, isTextNode, isVisible, removeAttribute, removeFromParent, removeFromTree, removeFromTree, removeProperty, scrollIntoView, scrollIntoView, setAttribute, setAttribute, setAttribute, setEnabled, setProperty, setProperty, setProperty, setPropertyBean, setPropertyJson, setPropertyList, setPropertyMap, setText, setVisible, toStringMethods inherited from class com.vaadin.flow.dom.Node
accept, appendChild, appendChild, appendVirtualChild, appendVirtualChild, ensureChildHasParent, equals, getNode, getParentNode, getStateProvider, hashCode, indexOfChild, insertChild, insertChild, isVirtualChild, removeAllChildren, removeChild, removeChild, removeChild, removeVirtualChild, removeVirtualChild, setChild
-
Constructor Details
-
TextElement
public TextElement() -
TextElement
Creates a text element with the given text content.- Parameters:
text- the text content
-
TextElement
Creates a text element at the specified position.- Parameters:
x- the x coordinatey- the y coordinatetext- the text content
-
-
Method Details
-
text
Sets the text content.- Parameters:
text- the text content- Returns:
- this element for method chaining
-
x
Sets the x coordinate of the text starting point.Uses write-only optimization. Use
xRW(double)if you need to read the value back.- Parameters:
x- the x coordinate- Returns:
- this element for method chaining
-
x
Sets the x coordinate with a unit.Uses write-only optimization. Use
xRW(String)if you need to read the value back.- Parameters:
x- the x coordinate (e.g., "50%")- Returns:
- this element for method chaining
-
xRW
Sets the x coordinate of the text starting point (read-write).- Parameters:
x- the x coordinate- Returns:
- this element for method chaining
-
xRW
Sets the x coordinate with a unit (read-write).- Parameters:
x- the x coordinate (e.g., "50%")- Returns:
- this element for method chaining
-
y
Sets the y coordinate of the text starting point.Uses write-only optimization. Use
yRW(double)if you need to read the value back.- Parameters:
y- the y coordinate- Returns:
- this element for method chaining
-
y
Sets the y coordinate with a unit.Uses write-only optimization. Use
yRW(String)if you need to read the value back.- Parameters:
y- the y coordinate (e.g., "50%")- Returns:
- this element for method chaining
-
yRW
Sets the y coordinate of the text starting point (read-write).- Parameters:
y- the y coordinate- Returns:
- this element for method chaining
-
yRW
Sets the y coordinate with a unit (read-write).- Parameters:
y- the y coordinate (e.g., "50%")- Returns:
- this element for method chaining
-
position
Sets the position of the text.Uses write-only optimization. Use
positionRW(double, double)if you need to read the values back.- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- this element for method chaining
-
positionRW
Sets the position of the text (read-write).- Parameters:
x- the x coordinatey- the y coordinate- Returns:
- this element for method chaining
-
dx
Sets the horizontal shift from the previous text position.Uses write-only optimization. Use
dxRW(double)if you need to read the value back.- Parameters:
dx- the horizontal offset- Returns:
- this element for method chaining
-
dxRW
Sets the horizontal shift from the previous text position (read-write).- Parameters:
dx- the horizontal offset- Returns:
- this element for method chaining
-
dy
Sets the vertical shift from the previous text position.Uses write-only optimization. Use
dyRW(double)if you need to read the value back.- Parameters:
dy- the vertical offset- Returns:
- this element for method chaining
-
dyRW
Sets the vertical shift from the previous text position (read-write).- Parameters:
dy- the vertical offset- Returns:
- this element for method chaining
-
rotate
Sets the rotation for each character.Uses write-only optimization. Use
rotateRW(String)if you need to read the value back.- Parameters:
rotate- the rotation angle(s) in degrees- Returns:
- this element for method chaining
-
rotateRW
Sets the rotation for each character (read-write).- Parameters:
rotate- the rotation angle(s) in degrees- Returns:
- this element for method chaining
-
textLength
Sets the total length of the text.Uses write-only optimization. Use
textLengthRW(double)if you need to read the value back.- Parameters:
length- the text length- Returns:
- this element for method chaining
-
textLengthRW
Sets the total length of the text (read-write).- Parameters:
length- the text length- Returns:
- this element for method chaining
-
textAnchor
Sets the text anchor (horizontal alignment).Uses write-only optimization. Use
textAnchorRW(TextAnchor)if you need to read the value back.- Parameters:
anchor- the text anchor- Returns:
- this element for method chaining
-
textAnchorRW
Sets the text anchor (horizontal alignment) (read-write).- Parameters:
anchor- the text anchor- Returns:
- this element for method chaining
-
dominantBaseline
Sets the dominant baseline (vertical alignment).Uses write-only optimization. Use
dominantBaselineRW(DominantBaseline)if you need to read the value back.- Parameters:
baseline- the dominant baseline- Returns:
- this element for method chaining
-
dominantBaselineRW
Sets the dominant baseline (vertical alignment) (read-write).- Parameters:
baseline- the dominant baseline- Returns:
- this element for method chaining
-
fontFamily
Sets the font family.Uses write-only optimization. Use
fontFamilyRW(String)if you need to read the value back.- Parameters:
fontFamily- the font family (e.g., "Arial", "sans-serif")- Returns:
- this element for method chaining
-
fontFamilyRW
Sets the font family (read-write).- Parameters:
fontFamily- the font family (e.g., "Arial", "sans-serif")- Returns:
- this element for method chaining
-
fontSize
Sets the font size.Uses write-only optimization. Use
fontSizeRW(double)if you need to read the value back.- Parameters:
size- the font size- Returns:
- this element for method chaining
-
fontSize
Sets the font size with a unit.Uses write-only optimization. Use
fontSizeRW(String)if you need to read the value back.- Parameters:
size- the font size (e.g., "12px", "1em")- Returns:
- this element for method chaining
-
fontSizeRW
Sets the font size (read-write).- Parameters:
size- the font size- Returns:
- this element for method chaining
-
fontSizeRW
Sets the font size with a unit (read-write).- Parameters:
size- the font size (e.g., "12px", "1em")- Returns:
- this element for method chaining
-
fontWeight
Sets the font weight.Uses write-only optimization. Use
fontWeightRW(FontWeight)if you need to read the value back.- Parameters:
weight- the font weight- Returns:
- this element for method chaining
-
fontWeightRW
Sets the font weight (read-write).- Parameters:
weight- the font weight- Returns:
- this element for method chaining
-
fontStyle
Sets the font style.Uses write-only optimization. Use
fontStyleRW(FontStyle)if you need to read the value back.- Parameters:
style- the font style- Returns:
- this element for method chaining
-
fontStyleRW
Sets the font style (read-write).- Parameters:
style- the font style- Returns:
- this element for method chaining
-
textDecoration
Sets the text decoration.Uses write-only optimization. Use
textDecorationRW(TextDecoration)if you need to read the value back.- Parameters:
decoration- the text decoration- Returns:
- this element for method chaining
-
textDecorationRW
Sets the text decoration (read-write).- Parameters:
decoration- the text decoration- Returns:
- this element for method chaining
-
letterSpacing
Sets the letter spacing.Uses write-only optimization. Use
letterSpacingRW(double)if you need to read the value back.- Parameters:
spacing- the spacing value- Returns:
- this element for method chaining
-
letterSpacing
Sets the letter spacing with a unit.Uses write-only optimization. Use
letterSpacingRW(String)if you need to read the value back.- Parameters:
spacing- the spacing (e.g., "0.1em", "2px")- Returns:
- this element for method chaining
-
letterSpacingRW
Sets the letter spacing (read-write).- Parameters:
spacing- the spacing value- Returns:
- this element for method chaining
-
letterSpacingRW
Sets the letter spacing with a unit (read-write).- Parameters:
spacing- the spacing (e.g., "0.1em", "2px")- Returns:
- this element for method chaining
-
wordSpacing
Sets the word spacing.Uses write-only optimization. Use
wordSpacingRW(double)if you need to read the value back.- Parameters:
spacing- the spacing value- Returns:
- this element for method chaining
-
wordSpacingRW
Sets the word spacing (read-write).- Parameters:
spacing- the spacing value- Returns:
- this element for method chaining
-
add
Adds child elements to this text element.Typically used to add
TSpanElementorTextPathElementchildren.- Parameters:
children- the child elements- Returns:
- this element for method chaining
-