Gradients

Gradients are complex color sequences which change linearly from one to another. 

In JavaFX API, each color break is defined by the Stop class. Also, by setting coordinates, you can adjust the gradient's direction. For example, in the following code the gradient goes from black to white and from the top-left corner to the bottom-right one:

// chapter2/paint/GradientDemo.javaRectangle rect = new Rectangle(300, 200);Stop[] stops = new Stop[]{    new Stop(0, Color.BLACK),     new Stop(1, Color.ANTIQUEWHITE)};LinearGradient lg1 = new LinearGradient(0, 0, 300, 200, false, CycleMethod.NO_CYCLE, stops);rect.setFill(lg1);

Get Mastering JavaFX 10 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.