|
Paint the stage: Paint, Color, and Gradients
Stage's fill attribute lets you determine how the content area's background is painted. Because this attribute is of type Paint, and because the javafx.scene.paint.Color, javafx.scene.paint.LinearGradient, and javafx.scene.paint.RadialGradiant classes subclass this abstract class, you can paint the background using either a solid color or a gradient pattern.
The Color class lets you specify a solid color in various ways. For example, you can create an object literal, assigning the color's red, green, and blue components to the literal's red, green, and blue Number attributes. Alternatively, you can work with functions such as those listed below:
* public static color(red: Number, green: Number, blue: Number, opacity: Number): Color returns a solid color in the sRGB color space with the specified red, green, blue, and opacity values in the range 0.0-1.0.
* public static fromAWTColor(c: java.awt.Color): Color returns a solid color derived from the provided java.awt.Color instance.
* public static hsb(hue: Number, saturation: Number, brightness: Number, opacity: Number): Color returns a solid color based on the specified values for the HSB color model. The saturation, brightness, and opacity components should be floating-point values ranging from 0.0 through 1.0. The hue component can be any floating-point number. The floor of this number is subtracted from it to create a fraction between 0 and 1. This fractional number is then multiplied by 360 to produce the hue angle in the HSB color model.
* public static rgb(red: Integer, green: Integer, blue: Integer, opacity: Number): Color returns a solid color in the sRGB color space with the specified red, green, and blue values in the range 0-255, and the opacity value in the range 0.0-1.0.
* public static web(color: java.lang.String, opacity: Number): Color returns a solid color specified in hexadecimal notation, and having the specified opacity.
If you refer back to the Hello, JavaFX! script from "Jump into JavaFX, Part 1," you'll discover that I assigned an instance of LinearGradient (via the object literal that I've reproduced below) to fill, to establish a gradient pattern with black at the top and blue-violet at the bottom for the content area's background: |
|