Java Reference
In-Depth Information
method to apply a DropShadow object instance to the donut Shape object. Similar
to the prior technique, you set the offset of the shadow by calling setOffsetX()
and setOffsetY() .
Note In the previous release, builder objects could be used to create shapes a bit
more easily. However, the builder classes were removed from JavaFX 8 due to perform-
ance and bloating issues. If you're maintaining code that utilizes builder classes, it is re-
commended that you to migrate away from them and make use of the standard objects,
as demonstrated in this recipe.
14-5. Assigning Colors to Objects
Problem
You want to fill your shapes with simple colors and gradient colors.
Solution
In JavaFX, all shapes can be filled with simple colors and gradient colors. The follow-
ing are the main classes used to fill shape nodes:
javafx.scene.paint.Color
javafx.scene.paint.LinearGradient
javafx.scene.paint.Stop
javafx.scene.paint.RadialGradient
The following code uses the preceding classes to add radial and linear gradient col-
ors as well as transparent (alpha channel level) colors to shapes. This recipe uses an el-
lipse, rectangle, and rounded rectangle. A solid black line (as depicted in Figure 14-5 )
also appears in the recipe to demonstrate the transparency of the shape's color.
public void start(Stage primaryStage) {
primaryStage.setTitle("Chapter 14-5 Assigning Colors
To Objects");
Search WWH ::




Custom Search