Beside geometric shapes (see the recipe Drawing simple shapes), one of the most fundamental node types available in JavaFX is the Text node. This node is used to draw letter shapes on the screen that can be manipulated just like other node types offered by the JavaFX platform. In this recipe, you will learn how to work with the Text
class to display text on your application's screen.
Before you can draw text using JavaFX, you must know how to create a basic JavaFX application and know how to add content to the application's scene. To refresh your memory, see the recipe Building a JavaFX application. To display text, you will need to import the Text
class found in the package javafx.scene.text
. That package also contains additional classes to support text rendering in JavaFX including Font, FontWeight, TextAlignment
, and TextOrigin
.