Part of the fun in working with JavaFX is the ease with which you can create your own visual components. As your needs outgrow the basic nodes that are available, you will find it necessary to create new components that capture more complex interactivity behaviors and functionalities. In this recipe, we will explore how to create customized graphical nodes that can be used wherever you can attach a node to the scene graph.
Before you can create customized nodes, you must be familiar with the basic shapes and text nodes presented in previous recipes. If you are not familiar with the materials, review the recipes Drawing simple shapes and Drawing letter shapes using the Text class. Also, take a look at recipe Handling user input in this chapter to review how to handle user interactivity.
A custom node works just like any other JavaFX node and can be added to a scene graph. To create customized nodes, you will need to import the classes Node
and...