Java Reference
In-Depth Information
In the code, we are using two leaf nodes: a Text-Node and a Rectangle-Node. JavaFX
offers class Group which functions as a branch node containing leaf nodes for more
complex scene graphs. You can see how to use the Group class in the recipe Creating
your own custom node .
See also
F Setting up JavaFX for NetBeans
F Setting up JavaFX for Eclipse
F Declaring and using JavaFX classes
F Creating and using JavaFX sequences
Drawing simple shapes
The JavaFX application framework was designed from the ground up to handle graphical
elements. JavaFX provides inherent support for basic geometrical shapes as a first-class API.
This recipe shows how to programmatically draw lines, rectangles, circles, and ellipses using
the Shape APIs found in the javafx.scene.shape package.
Getting ready
Before you can draw your shapes 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 first recipe of this chapter, Building a JavaFX application .
How to do it...
The following code snippet shows how to draw a line, a rectangle, a circle, and an ellipse
on the screen. You can get the full listing of the code from ch002/source-code/src/
shapes/SimpleShapes.fx .
def spacer = 100;
Stage {
title: "Simple Shapes!"
width: 500
height: 300
x: 100;
y: 200
scene: Scene {
content: [
Line {
startX: 10
startY: 10
Search WWH ::

Custom Search