Java Reference
In-Depth Information
text.content = "{text.content}{e.char}";
}else if(e.char == "\b") {
text.content = text.content.substring(0,
text.content.length()-1);
}
However, this may not be portable across different locales and languages.
Text Display
There are two ways to handle text display in JavaFX. First, to merely display text
to the screen, use the javafx.scene.text.Text class. However, if you need
user editable text, it is easiest to use the javafx.scene.control.TextBox class.
Text
A Text is a shape that displays a string. A text has a font, geometry with a Text
Origin setting, and instance variables to control line wrapping. Newline charac-
ters within the string cause the line to wrap; otherwise, wrapping is governed by
the wrappingWidth variable.
A bare bones Text uses the default font and size and is black (see Figure 5.13). It
is declared as
Text {
translateX: 10, translateY: 30
content: "This is my Text"
}
Figure 5.13
Bare Bones Text
It is necessary to move the text to see it, and this will be explained in the section
on TextOrigin a little later in this chapter.
To make this more interesting, let's adjust the font size, and instead of using the
default fill of black, let's set the fill to transparent and the stroke to black (see
Figure 5.14).
 
 
Search WWH ::




Custom Search