Java Reference
In-Depth Information
There's more...
There are some interesting aspects of text rendering with which you should familiarize yourself
before you leave this recipe.
Text origin
Unlike other node types, the text node has a variable coordinate system which can be
changed dynamically to accommodate where the text is rendered relative to its y coordinate
using the textOrigin:TextOrigin property. The following code snippet shows how this
works. You can get the full list in ch02/source-code/src/text/TextOriginDemo.fx .
Line{startX:50 startY:0 endX:50 endY:200 stroke:Color.SILVER}
Line{startX:0 startY:25 endX:400 endY:25 stroke:Color.SILVER}
Text {
x:50 y: 25
font: Font {size: 20 name:"Arial Black"}
fill:Color.BROWN
textOrigin: TextOrigin.TOP
content: "This text uses TextOrigin.TOP"
}
The TextOrigin class includes the following options:
F TextOrigin.BASELINE —with this option (default), the coordinate system for the
text originates from the bottom left-hand corner of the bounding box for the first line
of the text. The bottom of all non-descending letters are drawn along the y coordinate
as shown in the previous figure.
F TextOrigin.TOP —the reference coordinate for the text originates from the upper
left-hand corner of the bounding box of the text, rendering the tallest letter of the first
line below the y coordinate as shown in the previous figure.
 
Search WWH ::




Custom Search