Spec-Zone .ru
спецификации, руководства, описания, API

JavaFX: Bringing Rich Experiences To All the Screens Of Your Life

Profile: desktop, common

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.

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:


 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

 var c = Color.fromAWTColor(java.awt.Color.BLUE }; //convert from an AWT color
 

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

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
publicALICEBLUEColor
publicANTIQUEWHITEColor
publicAQUAColor
publicAQUAMARINEColor
publicAZUREColor
publicBEIGEColor
publicBISQUEColor
publicBLACKColor
publicBLANCHEDALMONDColor
publicBLUEColor
publicBLUEVIOLETColor
publicBROWNColor
publicBURLYWOODColor
publicCADETBLUEColor
publicCHARTREUSEColor
publicCHOCOLATEColor
publicCORALColor
publicCORNFLOWERBLUEColor
publicCORNSILKColor
publicCRIMSONColor
publicCYANColor
publicDARKBLUEColor
publicDARKCYANColor
publicDARKGOLDENRODColor
publicDARKGRAYColor
publicDARKGREENColor
publicDARKGREYColor
publicDARKKHAKIColor
publicDARKMAGENTAColor
publicDARKOLIVEGREENColor
publicDARKORANGEColor
publicDARKORCHIDColor
publicDARKREDColor
publicDARKSALMONColor
publicDARKSEAGREENColor
publicDARKSLATEBLUEColor
publicDARKSLATEGRAYColor
publicDARKSLATEGREYColor
publicDARKTURQUOISEColor
publicDARKVIOLETColor
publicDEEPPINKColor
publicDEEPSKYBLUEColor
publicDIMGRAYColor
publicDIMGREYColor
publicDODGERBLUEColor
publicFIREBRICKColor
publicFLORALWHITEColor
publicFORESTGREENColor
publicFUCHSIAColor
publicGAINSBOROColor
publicGHOSTWHITEColor
publicGOLDColor
publicGOLDENRODColor
publicGRAYColor
publicGREENColor
publicGREENYELLOWColor
publicGREYColor
publicHONEYDEWColor
publicHOTPINKColor
publicINDIANREDColor
publicINDIGOColor
publicIVORYColor
publicKHAKIColor
publicLAVENDERColor
publicLAVENDERBLUSHColor
publicLAWNGREENColor
publicLEMONCHIFFONColor
publicLIGHTBLUEColor
publicLIGHTCORALColor
publicLIGHTCYANColor
publicLIGHTGOLDENRODYELLOWColor
publicLIGHTGRAYColor
publicLIGHTGREENColor
publicLIGHTGREYColor
publicLIGHTPINKColor
publicLIGHTSALMONColor
publicLIGHTSEAGREENColor
publicLIGHTSKYBLUEColor
publicLIGHTSLATEGRAYColor
publicLIGHTSLATEGREYColor
publicLIGHTSTEELBLUEColor
publicLIGHTYELLOWColor
publicLIMEColor
publicLIMEGREENColor
publicLINENColor
publicMAGENTAColor
publicMAROONColor
publicMEDIUMAQUAMARINEColor
publicMEDIUMBLUEColor
publicMEDIUMORCHIDColor
publicMEDIUMPURPLEColor
publicMEDIUMSEAGREENColor
publicMEDIUMSLATEBLUEColor
publicMEDIUMSPRINGGREENColor
publicMEDIUMTURQUOISEColor
publicMEDIUMVIOLETREDColor
publicMIDNIGHTBLUEColor
publicMINTCREAMColor
publicMISTYROSEColor
publicMOCCASINColor
publicNAVAJOWHITEColor
publicNAVYColor
publicOLDLACEColor
publicOLIVEColor
publicOLIVEDRABColor
publicORANGEColor
publicORANGEREDColor
publicORCHIDColor
publicPALEGOLDENRODColor
publicPALEGREENColor
publicPALETURQUOISEColor
publicPALEVIOLETREDColor
publicPAPAYAWHIPColor
publicPEACHPUFFColor
publicPERUColor
publicPINKColor
publicPLUMColor
publicPOWDERBLUEColor
publicPURPLEColor
publicREDColor
publicROSYBROWNColor
publicROYALBLUEColor
publicSADDLEBROWNColor
publicSALMONColor
publicSANDYBROWNColor
publicSEAGREENColor
publicSEASHELLColor
publicSIENNAColor
publicSILVERColor
publicSKYBLUEColor
publicSLATEBLUEColor
publicSLATEGRAYColor
publicSLATEGREYColor
publicSNOWColor
publicSPRINGGREENColor
publicSTEELBLUEColor
publicTANColor
publicTEALColor
publicTHISTLEColor
publicTOMATOColor
publicTRANSPARENTColor

A fully transparent color.

publicTURQUOISEColor
publicVIOLETColor
publicWHEATColor
publicWHITEColor
publicWHITESMOKEColor
publicYELLOWColor
publicYELLOWGREENColor

Variable Summary

accessnametypeCan ReadCan InitCan WriteDefault Valuedescription
public-initblueNumber0.0

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

public-initgreenNumber0.0

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

public-initopacityNumber1.0

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

public-initredNumber0.0

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

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 equals(obj: java.lang.Object) : Boolean
Parameters
obj
Returns
Boolean
 
public hashCode() : Integer
Returns
Integer
 
public impl_getPlatformPaint() : java.lang.Object
Returns
Object
 
public ofTheWay(endVal: java.lang.Object, t: Number) : java.lang.Object
Parameters
endVal
t
Returns
Object
 
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 be null.

Returns
String
the string representation

Profile: common

 

Inherited Functions

javafx.scene.paint.Paint

public abstract impl_getPlatformPaint() : java.lang.Object
Returns
Object
 

javafx.animation.Interpolatable

public abstract ofTheWay(endVal: java.lang.Object, t: Number) : java.lang.Object

The function calcuates an interpolated value along the t between 0.0 and 1.0.

The function calcuates an interpolated value along the t between 0.0 and 1.0. When t = 1.0, endVal is returned.

Parameters
endVal
target value
t

fraction between 0.0 and 1.0

Returns
Object
interpolated value

Profile: common