APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.scene.paint

public final Class Color

extends Paint
Class Inheritance
Imports
java.util.Objects, com.sun.javafx.css.parser.CssColorParser, com.sun.javafx.util.InterpolationUtils, .Utils, com.sun.javafx.tk.Toolkit, javafx.beans.NamedArg

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. implicit 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

Field Summary

Modifier and TypeField and Description
public static final Color
ALICEBLUE

The color alice blue with an RGB value of #F0F8FF

public static final Color
ANTIQUEWHITE

The color antique white with an RGB value of #FAEBD7

public static final Color
AQUA

The color aqua with an RGB value of #00FFFF

public static final Color
AQUAMARINE

The color aquamarine with an RGB value of #7FFFD4

public static final Color
AZURE

The color azure with an RGB value of #F0FFFF

public static final Color
BEIGE

The color beige with an RGB value of #F5F5DC

public static final Color
BISQUE

The color bisque with an RGB value of #FFE4C4

public static final Color
BLACK

The color black with an RGB value of #000000

public static final Color
BLANCHEDALMOND

The color blanched almond with an RGB value of #FFEBCD

public static final Color
BLUE

The color blue with an RGB value of #0000FF

private final float
public static final Color
BLUEVIOLET

The color blue violet with an RGB value of #8A2BE2

public static final Color
BROWN

The color brown with an RGB value of #A52A2A

public static final Color
BURLYWOOD

The color burly wood with an RGB value of #DEB887

public static final Color
CADETBLUE

The color cadet blue with an RGB value of #5F9EA0

public static final Color
CHARTREUSE

The color chartreuse with an RGB value of #7FFF00

public static final Color
CHOCOLATE

The color chocolate with an RGB value of #D2691E

public static final Color
CORAL

The color coral with an RGB value of #FF7F50

public static final Color
CORNFLOWERBLUE

The color cornflower blue with an RGB value of #6495ED

public static final Color
CORNSILK

The color cornsilk with an RGB value of #FFF8DC

public static final Color
CRIMSON

The color crimson with an RGB value of #DC143C

public static final Color
CYAN

The color cyan with an RGB value of #00FFFF

public static final Color
DARKBLUE

The color dark blue with an RGB value of #00008B

public static final Color
DARKCYAN

The color dark cyan with an RGB value of #008B8B

private static final double
DARKER_BRIGHTER_FACTOR

Brightness change factor for darker() and brighter() methods.

public static final Color
DARKGOLDENROD

The color dark goldenrod with an RGB value of #B8860B

public static final Color
DARKGRAY

The color dark gray with an RGB value of #A9A9A9

public static final Color
DARKGREEN

The color dark green with an RGB value of #006400

public static final Color
DARKGREY

The color dark grey with an RGB value of #A9A9A9

public static final Color
DARKKHAKI

The color dark khaki with an RGB value of #BDB76B

public static final Color
DARKMAGENTA

The color dark magenta with an RGB value of #8B008B

public static final Color
DARKOLIVEGREEN

The color dark olive green with an RGB value of #556B2F

public static final Color
DARKORANGE

The color dark orange with an RGB value of #FF8C00

public static final Color
DARKORCHID

The color dark orchid with an RGB value of #9932CC

public static final Color
DARKRED

The color dark red with an RGB value of #8B0000

public static final Color
DARKSALMON

The color dark salmon with an RGB value of #E9967A

public static final Color
DARKSEAGREEN

The color dark sea green with an RGB value of #8FBC8F

public static final Color
DARKSLATEBLUE

The color dark slate blue with an RGB value of #483D8B

public static final Color
DARKSLATEGRAY

The color dark slate gray with an RGB value of #2F4F4F

public static final Color
DARKSLATEGREY

The color dark slate grey with an RGB value of #2F4F4F

public static final Color
DARKTURQUOISE

The color dark turquoise with an RGB value of #00CED1

public static final Color
DARKVIOLET

The color dark violet with an RGB value of #9400D3

public static final Color
DEEPPINK

The color deep pink with an RGB value of #FF1493

public static final Color
DEEPSKYBLUE

The color deep sky blue with an RGB value of #00BFFF

public static final Color
DIMGRAY

The color dim gray with an RGB value of #696969

public static final Color
DIMGREY

The color dim grey with an RGB value of #696969

public static final Color
DODGERBLUE

The color dodger blue with an RGB value of #1E90FF

public static final Color
FIREBRICK

The color firebrick with an RGB value of #B22222

public static final Color
FLORALWHITE

The color floral white with an RGB value of #FFFAF0

public static final Color
FORESTGREEN

The color forest green with an RGB value of #228B22

public static final Color
FUCHSIA

The color fuchsia with an RGB value of #FF00FF

public static final Color
GAINSBORO

The color gainsboro with an RGB value of #DCDCDC

public static final Color
GHOSTWHITE

The color ghost white with an RGB value of #F8F8FF

public static final Color
GOLD

The color gold with an RGB value of #FFD700

public static final Color
GOLDENROD

The color goldenrod with an RGB value of #DAA520

public static final Color
GRAY

The color gray with an RGB value of #808080

public static final Color
GREEN

The color green with an RGB value of #008000

private final float
public static final Color
GREENYELLOW

The color green yellow with an RGB value of #ADFF2F

public static final Color
GREY

The color grey with an RGB value of #808080

public static final Color
HONEYDEW

The color honeydew with an RGB value of #F0FFF0

public static final Color
HOTPINK

The color hot pink with an RGB value of #FF69B4

public static final Color
INDIANRED

The color indian red with an RGB value of #CD5C5C

public static final Color
INDIGO

The color indigo with an RGB value of #4B0082

public static final Color
IVORY

The color ivory with an RGB value of #FFFFF0

public static final Color
KHAKI

The color khaki with an RGB value of #F0E68C

public static final Color
LAVENDER

The color lavender with an RGB value of #E6E6FA

public static final Color
LAVENDERBLUSH

The color lavender blush with an RGB value of #FFF0F5

public static final Color
LAWNGREEN

The color lawn green with an RGB value of #7CFC00

public static final Color
LEMONCHIFFON

The color lemon chiffon with an RGB value of #FFFACD

public static final Color
LIGHTBLUE

The color light blue with an RGB value of #ADD8E6

public static final Color
LIGHTCORAL

The color light coral with an RGB value of #F08080

public static final Color
LIGHTCYAN

The color light cyan with an RGB value of #E0FFFF

public static final Color
LIGHTGOLDENRODYELLOW

The color light goldenrod yellow with an RGB value of #FAFAD2

public static final Color
LIGHTGRAY

The color light gray with an RGB value of #D3D3D3

public static final Color
LIGHTGREEN

The color light green with an RGB value of #90EE90

public static final Color
LIGHTGREY

The color light grey with an RGB value of #D3D3D3

public static final Color
LIGHTPINK

The color light pink with an RGB value of #FFB6C1

public static final Color
LIGHTSALMON

The color light salmon with an RGB value of #FFA07A

public static final Color
LIGHTSEAGREEN

The color light sea green with an RGB value of #20B2AA

public static final Color
LIGHTSKYBLUE

The color light sky blue with an RGB value of #87CEFA

public static final Color
LIGHTSLATEGRAY

The color light slate gray with an RGB value of #778899

public static final Color
LIGHTSLATEGREY

The color light slate grey with an RGB value of #778899

public static final Color
LIGHTSTEELBLUE

The color light steel blue with an RGB value of #B0C4DE

public static final Color
LIGHTYELLOW

The color light yellow with an RGB value of #FFFFE0

public static final Color
LIME

The color lime with an RGB value of #00FF00

public static final Color
LIMEGREEN

The color lime green with an RGB value of #32CD32

public static final Color
LINEN

The color linen with an RGB value of #FAF0E6

public static final Color
MAGENTA

The color magenta with an RGB value of #FF00FF

public static final Color
MAROON

The color maroon with an RGB value of #800000

public static final Color
MEDIUMAQUAMARINE

The color medium aquamarine with an RGB value of #66CDAA

public static final Color
MEDIUMBLUE

The color medium blue with an RGB value of #0000CD

public static final Color
MEDIUMORCHID

The color medium orchid with an RGB value of #BA55D3

public static final Color
MEDIUMPURPLE

The color medium purple with an RGB value of #9370DB

public static final Color
MEDIUMSEAGREEN

The color medium sea green with an RGB value of #3CB371

public static final Color
MEDIUMSLATEBLUE

The color medium slate blue with an RGB value of #7B68EE

public static final Color
MEDIUMSPRINGGREEN

The color medium spring green with an RGB value of #00FA9A

public static final Color
MEDIUMTURQUOISE

The color medium turquoise with an RGB value of #48D1CC

public static final Color
MEDIUMVIOLETRED

The color medium violet red with an RGB value of #C71585

public static final Color
MIDNIGHTBLUE

The color midnight blue with an RGB value of #191970

public static final Color
MINTCREAM

The color mint cream with an RGB value of #F5FFFA

public static final Color
MISTYROSE

The color misty rose with an RGB value of #FFE4E1

public static final Color
MOCCASIN

The color moccasin with an RGB value of #FFE4B5

public static final Color
OLDLACE

The color old lace with an RGB value of #FDF5E6

public static final Color
OLIVE

The color olive with an RGB value of #808000

public static final Color
OLIVEDRAB

The color olive drab with an RGB value of #6B8E23

private final float
public static final Color
ORANGE

The color orange with an RGB value of #FFA500

public static final Color
ORANGERED

The color orange red with an RGB value of #FF4500

public static final Color
ORCHID

The color orchid with an RGB value of #DA70D6

public static final Color
PALEGOLDENROD

The color pale goldenrod with an RGB value of #EEE8AA

public static final Color
PALEGREEN

The color pale green with an RGB value of #98FB98

public static final Color
PALETURQUOISE

The color pale turquoise with an RGB value of #AFEEEE

public static final Color
PALEVIOLETRED

The color pale violet red with an RGB value of #DB7093

public static final Color
PAPAYAWHIP

The color papaya whip with an RGB value of #FFEFD5

public static final Color
PEACHPUFF

The color peach puff with an RGB value of #FFDAB9

public static final Color
PERU

The color peru with an RGB value of #CD853F

public static final Color
PINK

The color pink with an RGB value of #FFC0CB

private Object
public static final Color
PLUM

The color plum with an RGB value of #DDA0DD

public static final Color
POWDERBLUE

The color powder blue with an RGB value of #B0E0E6

public static final Color
PURPLE

The color purple with an RGB value of #800080

public static final Color
RED

The color red with an RGB value of #FF0000

private final float
public static final Color
ROSYBROWN

The color rosy brown with an RGB value of #BC8F8F

public static final Color
ROYALBLUE

The color royal blue with an RGB value of #4169E1

public static final Color
SADDLEBROWN

The color saddle brown with an RGB value of #8B4513

public static final Color
SALMON

The color salmon with an RGB value of #FA8072

public static final Color
SANDYBROWN

The color sandy brown with an RGB value of #F4A460

private static final double
SATURATE_DESATURATE_FACTOR

Saturation change factor for saturate() and desaturate() methods.

public static final Color
SEAGREEN

The color sea green with an RGB value of #2E8B57

public static final Color
SEASHELL

The color sea shell with an RGB value of #FFF5EE

public static final Color
SIENNA

The color sienna with an RGB value of #A0522D

public static final Color
SILVER

The color silver with an RGB value of #C0C0C0

public static final Color
SKYBLUE

The color sky blue with an RGB value of #87CEEB

public static final Color
SLATEBLUE

The color slate blue with an RGB value of #6A5ACD

public static final Color
SLATEGRAY

The color slate gray with an RGB value of #708090

public static final Color
SLATEGREY

The color slate grey with an RGB value of #708090

public static final Color
SNOW

The color snow with an RGB value of #FFFAFA

public static final Color
SPRINGGREEN

The color spring green with an RGB value of #00FF7F

public static final Color
STEELBLUE

The color steel blue with an RGB value of #4682B4

public static final Color
TAN

The color tan with an RGB value of #D2B48C

public static final Color
TEAL

The color teal with an RGB value of #008080

public static final Color
THISTLE

The color thistle with an RGB value of #D8BFD8

public static final Color
TOMATO

The color tomato with an RGB value of #FF6347

public static final Color
TRANSPARENT

A fully transparent color with an ARGB value of #00000000.

public static final Color
TURQUOISE

The color turquoise with an RGB value of #40E0D0

public static final Color
VIOLET

The color violet with an RGB value of #EE82EE

public static final Color
WHEAT

The color wheat with an RGB value of #F5DEB3

public static final Color
WHITE

The color white with an RGB value of #FFFFFF

public static final Color
WHITESMOKE

The color white smoke with an RGB value of #F5F5F5

public static final Color
YELLOW

The color yellow with an RGB value of #FFFF00

public static final Color
YELLOWGREEN

The color yellow green with an RGB value of #9ACD32

Constructor Summary

AccessConstructor and Description
public
Color(double
red component ranging from 0 to 1
red
,
double
green component ranging from 0 to 1
green
,
double
blue component ranging from 0 to 1
blue
,
double
opacity ranging from 0 to 1
opacity
)

Creates a Color with the specified red, green, blue, and alpha values in the range 0.0-1.0.

private
Color(float
red component ranging from 0 to 1
red
,
float
green component ranging from 0 to 1
green
,
float
blue component ranging from 0 to 1
blue
)

Creates a new instance of color.

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
public Color

Returns:

a Color that is a brighter version of this Color
brighter
()

Creates a new Color that is a brighter version of this Color.

private static void
checkRGB(int red, int green, int blue)

private static void
checkSB(double saturation, double brightness)

public static Color

Returns:

the Color
color
(double
the red component, in the range 0.0-1.0
red
,
double
the green component, in the range 0.0-1.0
green
,
double
the blue component, in the range 0.0-1.0
blue
,
double
the opacity component, in the range 0.0-1.0
opacity
)

Creates an sRGB color with the specified red, green and blue values in the range 0.0-1.0, and a given opacity.

public static Color

Returns:

the Color
color
(double
the red component, in the range 0.0-1.0
red
,
double
the green component, in the range 0.0-1.0
green
,
double
the blue component, in the range 0.0-1.0
blue
)

Creates an opaque sRGB color with the specified red, green and blue values in the range 0.0-1.0.

public Color

Returns:

a Color that is a darker version of this Color
darker
()

Creates a new Color that is a darker version of this Color.

public Color

Returns:

a Color based based on this Color with hue, saturation, brightness and opacity values altered.
deriveColor
(double
the hue shift
hueShift
,
double
the saturation factor
saturationFactor
,
double
the brightness factor
brightnessFactor
,
double
the opacity factor
opacityFactor
)

Creates a new Color based on this Color with hue, saturation, brightness and opacity values altered.

public Color

Returns:

a Color that is a less saturated version of this Color
desaturate
()

Creates a new Color that is a less saturated version of this Color.

public boolean

Returns:

true if this object is equal to the obj argument; false otherwise.
equals
(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public final double

Returns:

the blue component of the Color, in the range 0.0-1.0
getBlue
()

The blue component of the Color, in the range 0.0-1.0.

public double

Returns:

Brightness value in the range in the range 0.0-1.0.
getBrightness
()

Gets the brightness component of this Color.

public final double

Returns:

the green component of the Color, in the range 0.0-1.0
getGreen
()

The green component of the Color, in the range 0.0-1.0.

public double

Returns:

Hue value in the range in the range 0.0-360.0.
getHue
()

Gets the hue component of this Color.

public final double

Returns:

the opacity of the Color, in the range 0.0-1.0
getOpacity
()

The opacity of the Color, in the range 0.0-1.0.

public final double

Returns:

the red component of the Color, in the range 0.0-1.0
getRed
()

The red component of the Color, in the range 0.0-1.0.

public double

Returns:

Saturation value in the range in the range 0.0-1.0.
getSaturation
()

Gets the saturation component of this Color.

public static Color

Returns:

the Color
gray
(double
color on gray scale in the range 0.0 (black) - 1.0 (white).
gray
,
double
the opacity component, in the range 0.0-1.0
opacity
)

Creates a grey color.

public static Color

Returns:

the Color
gray
(double
color on gray scale in the range 0.0 (black) - 1.0 (white).
gray
)

Creates an opaque grey color.

public static Color

Returns:

the Color
grayRgb
(int
the gray component, in the range 0-255
gray
)

This is a shortcut for rgb(gray, gray, gray).

public static Color

Returns:

the Color
grayRgb
(int
the gray component, in the range 0-255
gray
,
double
the opacity component, in the range 0.0-1.0
opacity
)

This is a shortcut for rgb(gray, gray, gray, opacity).

public Color

Returns:

a Color that is grayscale equivalent of this Color
grayscale
()

Creates a new Color that is grayscale equivalent of this Color.

public int

Returns:

a hash code for this Color object.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this Color object.

public static Color

Returns:

the Color
hsb
(double
the hue, in degrees
hue
,
double
the saturation, 0.0 to 1.0
saturation
,
double
the brightness, 0.0 to 1.0
brightness
,
double
the opacity, 0.0 to 1.0
opacity
)

Creates a Color based on the specified values in the HSB color model, and a given opacity.

public static Color

Returns:

the Color
hsb
(double
the hue, in degrees
hue
,
double
the saturation, 0.0 to 1.0
saturation
,
double
the brightness, 0.0 to 1.0
brightness
)

Creates an opaque Color based on the specified values in the HSB color model.

public Color

Returns:

the intermediate value
interpolate
(Color
the target value
endValue
,
double
the interpolation factor
t
)

Implements javafx.animation.Interpolatable.interpolate.

Returns an intermediate value between the value of this Color and the specified endValue using the linear interpolation factor t, ranging from 0 (inclusive) to 1 (inclusive).

public Paint
interpolate(Paint endValue, double t)

Implements javafx.animation.Interpolatable.interpolate.

Returns an intermediate value between the value of this Interpolatable and the specified endValue using the linear interpolation factor t.

public Color

Returns:

a Color that is inversion of this Color
invert
()

Creates a new Color that is inversion of this Color.

public final boolean
isOpaque()

Implements abstract javafx.scene.paint.Paint.isOpaque.

Gets whether this Paint is completely opaque.

public static Color

Returns:

the Color
rgb
(int
the red component, in the range 0-255
red
,
int
the green component, in the range 0-255
green
,
int
the blue component, in the range 0-255
blue
,
double
the opacity component, in the range 0.0-1.0
opacity
)

Creates an sRGB color with the specified RGB values in the range 0-255, and a given opacity.

public static Color

Returns:

the Color
rgb
(int
the red component, in the range 0-255
red
,
int
the green component, in the range 0-255
green
,
int
the blue component, in the range 0-255
blue
)

Creates an opaque sRGB color with the specified RGB values in the range 0-255.

public Color

Returns:

a Color that is a more saturated version of this Color
saturate
()

Creates a new Color that is a more saturated version of this Color.

private static int
to32BitInteger(int red, int green, int blue, int alpha)

public String

Returns:

the string representation
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this Color.

public static Color

Returns:

a Color object holding the value represented by the string argument
valueOf
(String
the string to convert
value
)

Hides javafx.scene.paint.Paint.valueOf.

Creates a color value from a string representation.

public static Color

Returns:

the RGB color specified with the colorString
web
(String
the name or numeric representation of the color in one of the supported formats
colorString
,
double
the opacity component in range from 0.0 (transparent) to 1.0 (opaque)
opacity
)

Creates an RGB color specified with an HTML or CSS attribute string.

public static Color

Returns:

an RGB color
web
(String
the name or numeric representation of the color in one of the supported formats
colorString
)

Creates an RGB color specified with an HTML or CSS attribute string.

Inherited from javafx.scene.paint.Paint:
acc_addListeneracc_isMutableacc_removeListener