Overview
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 float 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.
Color
s can be created with the constructor or with one of several
utility methods. The following lines of code all create the same
blue color:
var c = Color.BLUE; //use the blue constant
var c = Color { red: 0 green: 0 blue: 1.0 }; // standard constructor
var c = Color.color(0,0,1.0); //use 0->1.0 values. implicit alpha of 1.0
var c = Color.color(0,0,1.0,1.0); //use 0->1.0 values, explicit alpha of 1.0
var c = Color.rgb(0,0,255); //use 0->255 integers, implict alpha of 1.0
var c = Color.rgb(0,0,255,1.0); //use 0->255 integers, explict alpha of 1.0
var c = Color.hsb(270,1.0,1.0); //hue = 270, saturation & value = 1.0. inplict alpha of 1.0
var c = Color.hsb(270,1.0,1.0,1.0); //hue = 270, saturation & value = 1.0, explict alpha of 1.0
var c = Color.web("0x0000FF",1.0);// blue as a hex web value, explict alpha
var c = Color.web("0x0000FF");// blue as a hex web value, implict alpha
var c = Color.web("#0000FF",1.0);// blue as a hex web value, explict alpha
var c = Color.web("#0000FF");// blue as a hex web value, implict alpha
var c = Color.web("0000FF",1.0);// blue as a hex web value, explict alpha
var c = Color.web("0000FF");// blue as a hex web value, implict alpha
The creation of a Color
will throw IllegalArgumentException
if any
of the values are out of range.
the code:
import javafx.scene.*;
import javafx.scene.shape.*;
import javafx.scene.paint.*;
Group {
content: [
Rectangle {
x: 5, y: 5, width: 50, height: 40
fill: Color.RED
stroke: Color.GREEN
strokeWidth: 3
},
Rectangle {
x: 65, y: 5, width: 50, height: 40
fill: Color.rgb(91, 127, 255)
stroke: Color.hsb(40, 0.7, 0.8)
strokeWidth: 3
}]
}
produces:
Profile: common
Script Variable Summary
access | name | type | Can Read | Can Init | Can Write | Default Value | description |
---|---|---|---|---|---|---|---|
public | ALICEBLUE | Color | |||||
public | ANTIQUEWHITE | Color | |||||
public | AQUA | Color | |||||
public | AQUAMARINE | Color | |||||
public | AZURE | Color | |||||
public | BEIGE | Color | |||||
public | BISQUE | Color | |||||
public | BLACK | Color | |||||
public | BLANCHEDALMOND | Color | |||||
public | BLUE | Color | |||||
public | BLUEVIOLET | Color | |||||
public | BROWN | Color | |||||
public | BURLYWOOD | Color | |||||
public | CADETBLUE | Color | |||||
public | CHARTREUSE | Color | |||||
public | CHOCOLATE | Color | |||||
public | CORAL | Color | |||||
public | CORNFLOWERBLUE | Color | |||||
public | CORNSILK | Color | |||||
public | CRIMSON | Color | |||||
public | CYAN | Color | |||||
public | DARKBLUE | Color | |||||
public | DARKCYAN | Color | |||||
public | DARKGOLDENROD | Color | |||||
public | DARKGRAY | Color | |||||
public | DARKGREEN | Color | |||||
public | DARKGREY | Color | |||||
public | DARKKHAKI | Color | |||||
public | DARKMAGENTA | Color | |||||
public | DARKOLIVEGREEN | Color | |||||
public | DARKORANGE | Color | |||||
public | DARKORCHID | Color | |||||
public | DARKRED | Color | |||||
public | DARKSALMON | Color | |||||
public | DARKSEAGREEN | Color | |||||
public | DARKSLATEBLUE | Color | |||||
public | DARKSLATEGRAY | Color | |||||
public | DARKSLATEGREY | Color | |||||
public | DARKTURQUOISE | Color | |||||
public | DARKVIOLET | Color | |||||
public | DEEPPINK | Color | |||||
public | DEEPSKYBLUE | Color | |||||
public | DIMGRAY | Color | |||||
public | DIMGREY | Color | |||||
public | DODGERBLUE | Color | |||||
public | FIREBRICK | Color | |||||
public | FLORALWHITE | Color | |||||
public | FORESTGREEN | Color | |||||
public | FUCHSIA | Color | |||||
public | GAINSBORO | Color | |||||
public | GHOSTWHITE | Color | |||||
public | GOLD | Color | |||||
public | GOLDENROD | Color | |||||
public | GRAY | Color | |||||
public | GREEN | Color | |||||
public | GREENYELLOW | Color | |||||
public | GREY | Color | |||||
public | HONEYDEW | Color | |||||
public | HOTPINK | Color | |||||
public | INDIANRED | Color | |||||
public | INDIGO | Color | |||||
public | IVORY | Color | |||||
public | KHAKI | Color | |||||
public | LAVENDER | Color | |||||
public | LAVENDERBLUSH | Color | |||||
public | LAWNGREEN | Color | |||||
public | LEMONCHIFFON | Color | |||||
public | LIGHTBLUE | Color | |||||
public | LIGHTCORAL | Color | |||||
public | LIGHTCYAN | Color | |||||
public | LIGHTGOLDENRODYELLOW | Color | |||||
public | LIGHTGRAY | Color | |||||
public | LIGHTGREEN | Color | |||||
public | LIGHTGREY | Color | |||||
public | LIGHTPINK | Color | |||||
public | LIGHTSALMON | Color | |||||
public | LIGHTSEAGREEN | Color | |||||
public | LIGHTSKYBLUE | Color | |||||
public | LIGHTSLATEGRAY | Color | |||||
public | LIGHTSLATEGREY | Color | |||||
public | LIGHTSTEELBLUE | Color | |||||
public | LIGHTYELLOW | Color | |||||
public | LIME | Color | |||||
public | LIMEGREEN | Color | |||||
public | LINEN | Color | |||||
public | MAGENTA | Color | |||||
public | MAROON | Color | |||||
public | MEDIUMAQUAMARINE | Color | |||||
public | MEDIUMBLUE | Color | |||||
public | MEDIUMORCHID | Color | |||||
public | MEDIUMPURPLE | Color | |||||
public | MEDIUMSEAGREEN | Color | |||||
public | MEDIUMSLATEBLUE | Color | |||||
public | MEDIUMSPRINGGREEN | Color | |||||
public | MEDIUMTURQUOISE | Color | |||||
public | MEDIUMVIOLETRED | Color | |||||
public | MIDNIGHTBLUE | Color | |||||
public | MINTCREAM | Color | |||||
public | MISTYROSE | Color | |||||
public | MOCCASIN | Color | |||||
public | NAVAJOWHITE | Color | |||||
public | NAVY | Color | |||||
public | OLDLACE | Color | |||||
public | OLIVE | Color | |||||
public | OLIVEDRAB | Color | |||||
public | ORANGE | Color | |||||
public | ORANGERED | Color | |||||
public | ORCHID | Color | |||||
public | PALEGOLDENROD | Color | |||||
public | PALEGREEN | Color | |||||
public | PALETURQUOISE | Color | |||||
public | PALEVIOLETRED | Color | |||||
public | PAPAYAWHIP | Color | |||||
public | PEACHPUFF | Color | |||||
public | PERU | Color | |||||
public | PINK | Color | |||||
public | PLUM | Color | |||||
public | POWDERBLUE | Color | |||||
public | PURPLE | Color | |||||
public | RED | Color | |||||
public | ROSYBROWN | Color | |||||
public | ROYALBLUE | Color | |||||
public | SADDLEBROWN | Color | |||||
public | SALMON | Color | |||||
public | SANDYBROWN | Color | |||||
public | SEAGREEN | Color | |||||
public | SEASHELL | Color | |||||
public | SIENNA | Color | |||||
public | SILVER | Color | |||||
public | SKYBLUE | Color | |||||
public | SLATEBLUE | Color | |||||
public | SLATEGRAY | Color | |||||
public | SLATEGREY | Color | |||||
public | SNOW | Color | |||||
public | SPRINGGREEN | Color | |||||
public | STEELBLUE | Color | |||||
public | TAN | Color | |||||
public | TEAL | Color | |||||
public | THISTLE | Color | |||||
public | TOMATO | Color | |||||
public | TRANSPARENT | Color |
A fully transparent color. |
||||
public | TURQUOISE | Color | |||||
public | VIOLET | Color | |||||
public | WHEAT | Color | |||||
public | WHITE | Color | |||||
public | WHITESMOKE | Color | |||||
public | YELLOW | Color | |||||
public | YELLOWGREEN | Color |
Variable Summary
access | name | type | Can Read | Can Init | Can Write | Default Value | description |
---|---|---|---|---|---|---|---|
public-init | blue | Number | 0.0 |
The blue component of the |
|||
public-init | green | Number | 0.0 |
The green component of the |
|||
public-init | opacity | Number | 1.0 |
The opacity of the |
|||
public-init | red | Number | 0.0 |
The red component of the |
Inherited Variables
Script Function Summary
- public color(red: Number, green: Number, blue: Number, opacity: Number) : Color
-
Creates an sRGB color with the specified red, green and blue values in the range
0.0-1.0
, and a given opacity.Creates an sRGB color with the specified red, green and blue values in the range
0.0-1.0
, and a given opacity.-
Parameters
- red
-
the red component, in the range
0.0-1.0
- green
-
the green component, in the range
0.0-1.0
- blue
-
the blue component, in the range
0.0-1.0
- opacity
-
the opacity component, in the range
0.0-1.0
-
Returns
- Color
-
the
Color
-
Throws
- java.lang.IllegalArgumentException if any value is out of range
Profile: common
- public color(red: Number, green: Number, blue: Number) : Color
-
Creates an opaque sRGB color with the specified red, green and blue values in the range
0.0-1.0
.Creates an opaque sRGB color with the specified red, green and blue values in the range
0.0-1.0
.-
Parameters
- red
-
the red component, in the range
0.0-1.0
- green
-
the green component, in the range
0.0-1.0
- blue
-
the blue component, in the range
0.0-1.0
-
Returns
- Color
-
the
Color
-
Throws
- java.lang.IllegalArgumentException if any value is out of range
Profile: common
- public hsb(hue: Integer, saturation: Number, brightness: Number, opacity: Number) : Color
-
Creates a
Color
based on the specified values in the HSB color model, and a given opacity.Creates a
Color
based on the specified values in the HSB color model, and a given opacity.-
Parameters
- hue
- the hue, in degrees
- saturation
-
the saturation,
0.0 to 1.0
- brightness
-
the brightness,
0.0 to 1.0
- opacity
-
the opacity,
0.0 to 1.0
-
Returns
- Color
-
the
Color
-
Throws
- java.lang.IllegalArgumentException if {@code saturation}, {@code brightness} or {@code opacity} are out of range
Profile: common
- public hsb(hue: Integer, saturation: Number, brightness: Number) : Color
-
Creates an opaque
Color
based on the specified values in the HSB color model.Creates an opaque
Color
based on the specified values in the HSB color model.-
Parameters
- hue
- the hue, in degrees
- saturation
-
the saturation,
0.0 to 1.0
- brightness
-
the brightness,
0.0 to 1.0
-
Returns
- Color
-
the
Color
-
Throws
- java.lang.IllegalArgumentException if {@code saturation} or {@code brightness} are out of range
Profile: common
- public rgb(red: Integer, green: Integer, blue: Integer, opacity: Number) : Color
-
Creates an sRGB color with the specified RGB values in the range
0-255
, and a given opacity.Creates an sRGB color with the specified RGB values in the range
0-255
, and a given opacity.-
Parameters
- red
-
the red component, in the range
0-255
- green
-
the green component, in the range
0-255
- blue
-
the blue component, in the range
0-255
- opacity
-
the opacity component, in the range
0.0-1.0
-
Returns
- Color
-
the
Color
-
Throws
- java.lang.IllegalArgumentException if any value is out of range
Profile: common
- public rgb(red: Integer, green: Integer, blue: Integer) : Color
-
Creates an opaque sRGB color with the specified RGB values in the range
0-255
.Creates an opaque sRGB color with the specified RGB values in the range
0-255
.-
Parameters
- red
-
the red component, in the range
0-255
- green
-
the green component, in the range
0-255
- blue
-
the blue component, in the range
0-255
-
Returns
- Color
-
the
Color
-
Throws
- java.lang.IllegalArgumentException if any value is out of range
Profile: common
- public web(colorRawName: java.lang.String, opacity: Number) : Color
-
Creates an RGB color specified with hexadecimal notation.
Creates an RGB color specified with hexadecimal notation. Opacity is in the range 0.0-1.0. ex:
var c = Color.web("0xff6688",1.0); var c = Color.web("#ff6688",1.0); var c = Color.web("ff6688",1.0);
-
Parameters
- colorRawName
- the hexadecimal string to identify the RGB color
- opacity
- the opacity component
-
Returns
- Color
Profile: common
- public web(color: java.lang.String) : Color
-
Creates an RGB color specified with hexadecimal notation.
Creates an RGB color specified with hexadecimal notation. Opacity is set to
1.0
. ex:var c = Color.web("0xff6688"); var c = Color.web("#ff6688"); var c = Color.web("ff6688");
-
Parameters
- color
- the hexadecimal string to identify the RGB color
-
Returns
- Color
Profile: common
Function Summary
- public toString() : java.lang.String
-
Returns a string representation of this
Color
.Returns a string representation of this
Color
. This method is intended to be used only for informational purposes. The content and format of the returned string might vary between implementations. The returned string might be empty but cannot benull
.-
Returns
- String
- the string representation
Profile: common
Inherited Functions
javafx.scene.paint.Paint
javafx.animation.Interpolatable
- public abstract ofTheWay(endVal: java.lang.Object, t: Number) : java.lang.Object
-
The function calcuates an interpolated value along the
t
between0.0
and1.0
.The function calcuates an interpolated value along the
t
between0.0
and1.0
. Whent
= 1.0,endVal
is returned.-
Parameters
- endVal
- target value
- t
-
fraction between
0.0
and1.0
-
Returns
- Object
- interpolated value
Profile: common