In previous recipes, we have seen the Color
class used to apply color to node instances through the fill
property. You may have noticed in some recipes however, that instead of a simple color instance, you can apply color effects to the fill
property. In this recipe, we are going to explore the gradient color effect.
This recipe uses the concept of gradient paint effects to demonstrate JavaFX's deep support for rich GUI functionalities. To use gradient paint effects presented in this recipe, you will need to import classes LinearGradient, RadialGradient
, and Stop
from the package javafx.scene.paint
.
The abbreviated code listing below shows how to use the gradient classes. You can access the full code listing from ch03/source-code/src/effects/GradientPaintDemo.fx
.
def w = 400; def h = 200; def linearGrad = LinearGradient { startX: 0.0, startY: 0.0, endX: 0.0, endY: 1.0 proportional: true stops: [ Stop {offset: 0.0 color...