Class Color

java.lang.Object
javafx.scene.paint.Paint
javafx.scene.paint.Color
All Implemented Interfaces:
Interpolatable<Color>

public final class Color extends Paint implements Interpolatable<Color>
The Color class is used to encapsulate colors in the default sRGB color space. Every color has an implicit alpha value of 1.0 or an explicit one provided in the constructor. The alpha value defines the transparency of a color and can be represented by a double value in the range 0.0-1.0 or 0-255. An alpha value of 1.0 or 255 means that the color is completely opaque and an alpha value of 0 or 0.0 means that the color is completely transparent. When constructing a Color with an explicit alpha or getting the color/alpha components of a Color, the color components are never premultiplied by the alpha component.

Colors can be created with the constructor or with one of several utility methods. The following lines of code all create the same blue color:


 
 Color c = Color.BLUE;   //use the blue constant
 Color c = new Color(0,0,1,1.0); // standard constructor, use 0->1.0 values, explicit alpha of 1.0

 Color c = Color.color(0,0,1.0); //use 0->1.0 values. implicit alpha of 1.0
 Color c = Color.color(0,0,1.0,1.0); //use 0->1.0 values, explicit alpha of 1.0

 Color c = Color.rgb(0,0,255); //use 0->255 integers, implicit alpha of 1.0
 Color c = Color.rgb(0,0,255,1.0); //use 0->255 integers, explicit alpha of 1.0

 Color c = Color.hsb(270,1.0,1.0); //hue = 270, saturation & value = 1.0. inplicit alpha of 1.0
 Color c = Color.hsb(270,1.0,1.0,1.0); //hue = 270, saturation & value = 1.0, explicit alpha of 1.0

 Color c = Color.web("0x0000FF",1.0);// blue as a hex web value, explicit alpha
 Color c = Color.web("0x0000FF");// blue as a hex web value, implicit alpha
 Color c = Color.web("0x00F");// blue as a short hex web value, implicit alpha
 Color c = Color.web("#0000FF",1.0);// blue as a hex web value, explicit alpha
 Color c = Color.web("#0000FF");// blue as a hex web value, implicit alpha
 Color c = Color.web("#00F");// blue as a short hex web value, implicit alpha
 Color c = Color.web("0000FF",1.0);// blue as a hex web value, explicit alpha
 Color c = Color.web("0000FF");// blue as a hex web value, implicit alpha
 Color c = Color.web("00F");// blue as a short hex web value, implicit alpha
 Color c = Color.web("rgba(0,0,255,1.0)");// blue as an rgb web value, explicit alpha
 Color c = Color.web("rgb(0,0,255)");// blue as an rgb web value, implicit alpha
 Color c = Color.web("rgba(0,0,100%,1.0)");// blue as an rgb percent web value, explicit alpha
 Color c = Color.web("rgb(0,0,100%)");// blue as an rgb percent web value, implicit alpha
 Color c = Color.web("hsla(270,100%,100%,1.0)");// blue as an hsl web value, explicit alpha
 Color c = Color.web("hsl(270,100%,100%)");// blue as an hsl web value, implicit alpha
 
 

The creation of a Color will throw IllegalArgumentException if any of the values are out of range.

For example:


 Rectangle rec1 = new Rectangle(5, 5, 50, 40);
 rec1.setFill(Color.RED);
 rec1.setStroke(Color.GREEN);
 rec1.setStrokeWidth(3);

 Rectangle rec2 = new Rectangle(65, 5, 50, 40);
 rec2.setFill(Color.rgb(91, 127, 255));
 rec2.setStroke(Color.hsb(40, 0.7, 0.8));
 rec2.setStrokeWidth(3);
 
Since:
JavaFX 2.0