Top Description Fields Constructors Methods
javafx.scene.paint

public final Class RadialGradient

extends Paint
Class Inheritance
Imports
java.util.List, .Objects, com.sun.javafx.scene.paint.GradientUtils, com.sun.javafx.tk.Toolkit, com.sun.javafx.util.InterpolationUtils, javafx.beans.NamedArg

The RadialGradient class provides a way to fill a shape with a circular radial color gradient pattern. The user may specify 2 or more gradient colors, and this paint will provide an interpolation between each color.

The user must specify the circle controlling the gradient pattern, which is defined by a center point and a radius. The user can also specify a separate focus point within that circle, which controls the location of the first color of the gradient. By default the focus is set to be the center of the circle.

The center and radius are specified relative to a unit square, unless the proportional variable is false. By default proportional is true, and the gradient will be scaled to fill whatever shape it is applied to. The focus point is always specified relative to the center point by an angle and a distance relative to the radius.

This paint will map the first color of the gradient to the focus point, and the last color to the perimeter of the circle, interpolating smoothly for any in-between colors specified by the user. Any line drawn from the focus point to the circumference will thus span all of the gradient colors.

The focus distance will be clamped to the range (-1, 1) so that the focus point is always strictly inside the circle.

The application provides an array of Stops specifying how to distribute the colors along the gradient. The Stop#offset variable must be the range 0.0 to 1.0 and act like keyframes along the gradient. They mark where the gradient should be exactly a particular color.

Since
JavaFX 2.0

Field Summary

Modifier and TypeField and Description
private double
private double
private CycleMethod
private double
private double
private int
hash

The cached hash code, used to improve performance in situations where we cache gradients, such as in the CSS routines.

private final boolean
private Object
platformPaint

A cached reference to the platform paint, no point recomputing twice

private boolean
private double
private List<Stop>

Constructor Summary

AccessConstructor and Description
public
RadialGradient(double
the angle in degrees from the center of the gradient to the focus point to which the first color is mapped
focusAngle
,
double
the distance from the center of the gradient to the focus point to which the first color is mapped
focusDistance
,
double
the X coordinate of the center point of the gradient's circle
centerX
,
double
the Y coordinate of the center point of the gradient's circle
centerY
,
double
the radius of the circle defining the extents of the color gradient
radius
,
boolean
whether the coordinates and sizes are proportional to the shape which this gradient fills
proportional
,
CycleMethod
cycle method applied to the gradient
cycleMethod
,
Stop...
the gradient's color specification
stops
)

Creates a new instance of RadialGradient.

public
RadialGradient(double
the angle in degrees from the center of the gradient to the focus point to which the first color is mapped
focusAngle
,
double
the distance from the center of the gradient to the focus point to which the first color is mapped
focusDistance
,
double
the X coordinate of the center point of the gradient's circle
centerX
,
double
the Y coordinate of the center point of the gradient's circle
centerY
,
double
the radius of the circle defining the extents of the color gradient
radius
,
boolean
whether the coordinates and sizes are proportional to the shape which this gradient fills
proportional
,
CycleMethod
cycle method applied to the gradient
cycleMethod
,
List<Stop>
the gradient's color specification
stops
)

Creates a new instance of RadialGradient.

private
RadialGradient(double focusAngle, double focusDistance, double centerX, double centerY, double radius, boolean proportional, CycleMethod cycleMethod, List<Stop> stops, int ignored)

Private constructor accepting a stop list that is already normalized.

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
private boolean

Returns:

Whether this gradient is opaque
determineOpacity
()

Iterate over all the stops.

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 X coordinate of the center point of the circle defining the gradient
getCenterX
()

Defines the X coordinate of the center point of the circle defining the gradient.

public final double

Returns:

the X coordinate of the center point of the circle defining the gradient
getCenterY
()

Defines the X coordinate of the center point of the circle defining the gradient.

public final CycleMethod

Returns:

the cycle method applied to this radial gradient
getCycleMethod
()

Defines the cycle method applied to the RadialGradient.

public final double

Returns:

the angle in degrees from the center of the gradient to the focus point to which the first color is mapped
getFocusAngle
()

Defines the angle in degrees from the center of the gradient to the focus point to which the first color is mapped.

public final double

Returns:

the distance from the center of the gradient to the focus point to which the first color is mapped
getFocusDistance
()

Defines the distance from the center of the gradient to the focus point to which the first color is mapped.

public final double

Returns:

the radius of the circle defining the extents of the color gradient
getRadius
()

Specifies the radius of the circle defining the extents of the color gradient.

public final List<Stop>

Returns:

the list of Stop values
getStops
()

A sequence of 2 or more Stop values specifying how to distribute the colors along the gradient.

public int

Returns:

a hash code for this RadialGradient object.
hashCode
()

Overrides java.lang.Object.hashCode.

Returns a hash code for this RadialGradient object.

public RadialGradient

Returns:

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

Implements javafx.animation.Interpolatable.interpolate.

Returns an intermediate value between the value of this RadialGradient 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, ranging from 0 (inclusive) to 1 (inclusive).

public final boolean
isOpaque()

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

Gets whether this Paint is completely opaque.

public final boolean

Returns:

true if the center and radius values are proportional, otherwise absolute
isProportional
()

Indicates whether the center and radius values are proportional or absolute.

private boolean
isSame(double focusAngle, double focusDistance, double centerX, double centerY, double radius, boolean proportional, CycleMethod cycleMethod, List<Stop> stops)

public String

Returns:

a string representation of this RadialGradient object.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this RadialGradient object.

public static RadialGradient

Returns:

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

Hides javafx.scene.paint.Paint.valueOf.

Creates a radial gradient value from a string representation.

Inherited from javafx.scene.paint.Paint:
acc_addListeneracc_isMutableacc_removeListener

Field Detail

centerXback to summary
private double centerX
centerYback to summary
private double centerY
cycleMethodback to summary
private CycleMethod cycleMethod
focusAngleback to summary
private double focusAngle
focusDistanceback to summary
private double focusDistance
hashback to summary
private int hash

The cached hash code, used to improve performance in situations where we cache gradients, such as in the CSS routines.

opaqueback to summary
private final boolean opaque
platformPaintback to summary
private Object platformPaint

A cached reference to the platform paint, no point recomputing twice

proportionalback to summary
private boolean proportional
radiusback to summary
private double radius
stopsback to summary
private List<Stop> stops

Constructor Detail

RadialGradientback to summary
public RadialGradient(double focusAngle, double focusDistance, double centerX, double centerY, double radius, boolean proportional, CycleMethod cycleMethod, Stop... stops)

Creates a new instance of RadialGradient.

Parameters
focusAngle:double

the angle in degrees from the center of the gradient to the focus point to which the first color is mapped

focusDistance:double

the distance from the center of the gradient to the focus point to which the first color is mapped

centerX:double

the X coordinate of the center point of the gradient's circle

centerY:double

the Y coordinate of the center point of the gradient's circle

radius:double

the radius of the circle defining the extents of the color gradient

proportional:boolean

whether the coordinates and sizes are proportional to the shape which this gradient fills

cycleMethod:CycleMethod

cycle method applied to the gradient

stops:Stop[]

the gradient's color specification

RadialGradientback to summary
public RadialGradient(double focusAngle, double focusDistance, double centerX, double centerY, double radius, boolean proportional, CycleMethod cycleMethod, List<Stop> stops)

Creates a new instance of RadialGradient.

Parameters
focusAngle:double

the angle in degrees from the center of the gradient to the focus point to which the first color is mapped

focusDistance:double

the distance from the center of the gradient to the focus point to which the first color is mapped

centerX:double

the X coordinate of the center point of the gradient's circle

centerY:double

the Y coordinate of the center point of the gradient's circle

radius:double

the radius of the circle defining the extents of the color gradient

proportional:boolean

whether the coordinates and sizes are proportional to the shape which this gradient fills

cycleMethod:CycleMethod

cycle method applied to the gradient

stops:List<Stop>

the gradient's color specification

RadialGradientback to summary
private RadialGradient(double focusAngle, double focusDistance, double centerX, double centerY, double radius, boolean proportional, CycleMethod cycleMethod, List<Stop> stops, int ignored)

Private constructor accepting a stop list that is already normalized. This constructor is only called from the interpolate method.

Method Detail

acc_getPlatformPaintback to summary
pack-priv Object acc_getPlatformPaint()

Implements abstract javafx.scene.paint.Paint.acc_getPlatformPaint.

Annotations
@Override
determineOpacityback to summary
private boolean determineOpacity()

Iterate over all the stops. If any one of them has a transparent color, then we return false. If there are no stops, we return false. Otherwise, we return true. Note that this is called AFTER Stop.normalize, which ensures that we always have at least 2 stops.

Returns:boolean

Whether this gradient is opaque

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

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

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is equal to the obj argument; false otherwise.

Annotations
@Override
getCenterXback to summary
public final double getCenterX()

Defines the X coordinate of the center point of the circle defining the gradient. If proportional is true (the default), this value specifies a point on a unit square that will be scaled to match the size of the shape that the gradient fills. The last color of the gradient is mapped to the perimeter of this circle.

Returns:double

the X coordinate of the center point of the circle defining the gradient

Default Value
0.0
getCenterYback to summary
public final double getCenterY()

Defines the X coordinate of the center point of the circle defining the gradient. If proportional is true (the default), this value specifies a point on a unit square that will be scaled to match the size of the the shape that the gradient fills. The last color of the gradient is mapped to the perimeter of this circle.

Returns:double

the X coordinate of the center point of the circle defining the gradient

Default Value
0.0
getCycleMethodback to summary
public final CycleMethod getCycleMethod()

Defines the cycle method applied to the RadialGradient. One of: CycleMethod.NO_CYCLE, CycleMethod.REFLECT, or CycleMethod.REPEAT.

Returns:CycleMethod

the cycle method applied to this radial gradient

Default Value
NO_CYCLE
getFocusAngleback to summary
public final double getFocusAngle()

Defines the angle in degrees from the center of the gradient to the focus point to which the first color is mapped.

Returns:double

the angle in degrees from the center of the gradient to the focus point to which the first color is mapped

getFocusDistanceback to summary
public final double getFocusDistance()

Defines the distance from the center of the gradient to the focus point to which the first color is mapped. A distance of 0.0 will be at the center of the gradient circle. A distance of 1.0 will be on the circumference of the gradient circle.

Returns:double

the distance from the center of the gradient to the focus point to which the first color is mapped

getRadiusback to summary
public final double getRadius()

Specifies the radius of the circle defining the extents of the color gradient. If proportional is true (the default), this value specifies a size relative to unit square that will be scaled to match the size of the the shape that the gradient fills.

Returns:double

the radius of the circle defining the extents of the color gradient

Default Value
1.0
getStopsback to summary
public final List<Stop> getStops()

A sequence of 2 or more Stop values specifying how to distribute the colors along the gradient. These values must be in the range 0.0 to 1.0. They act like keyframes along the gradient: they mark where the gradient should be exactly a particular color.

Each stop in the sequence must have an offset that is greater than the previous stop in the sequence.

The list is unmodifiable and will throw UnsupportedOperationException on each modification attempt.

Returns:List<Stop>

the list of Stop values

Default Value
empty
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code for this RadialGradient object.

Returns:int

a hash code for this RadialGradient object.

Annotations
@Override
interpolateback to summary
public RadialGradient interpolate(RadialGradient endValue, double t)

Implements javafx.animation.Interpolatable.interpolate.

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

Parameters
endValue:RadialGradient

the target value

t:double

the interpolation factor

Returns:RadialGradient

the intermediate value

Exceptions
NullPointerException:
if endValue is null
Since
24
interpolateback to summary
public Paint interpolate(Paint endValue, double t)

Implements javafx.animation.Interpolatable.interpolate.

Doc from javafx.animation.Interpolatable.interpolate.

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

The returned value might not be a new instance; the implementation might also return one of the two existing instances if the intermediate value would be equal to one of the existing values. However, this is an optimization and applications should not assume any particular identity of the returned value.

Annotations
@Override
Exceptions
NullPointerException:
if endValue is null
Since
24
isOpaqueback to summary
public final boolean isOpaque()

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

Doc from javafx.scene.paint.Paint.isOpaque.

Gets whether this Paint is completely opaque. An opaque paint is one that has no alpha component in any of its colors. It may be possible for a Paint to be opaque and yet return false, if it cannot be easily determined whether the paint is actually opaque. For example, the ImagePattern may not be able to cheaply determine its opacity.

Annotations
@Override
Since
JavaFX 8.0
isProportionalback to summary
public final boolean isProportional()

Indicates whether the center and radius values are proportional or absolute. If this flag is true, the center point and radius are defined in a coordinate space where coordinates in the range [0..1] are scaled to map onto the bounds of the shape that the gradient fills. If this flag is false, then the center coordinates and the radius are specified in the local coordinate system of the node.

Returns:boolean

true if the center and radius values are proportional, otherwise absolute

Default Value
true
isSameback to summary
private boolean isSame(double focusAngle, double focusDistance, double centerX, double centerY, double radius, boolean proportional, CycleMethod cycleMethod, List<Stop> stops)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this RadialGradient object.

Returns:String

a string representation of this RadialGradient object.

Annotations
@Override
valueOfback to summary
public static RadialGradient valueOf(String value)

Hides javafx.scene.paint.Paint.valueOf.

Creates a radial gradient value from a string representation.

The format of the string representation is based on JavaFX CSS specification for radial gradient which is

radial-gradient([focus-angle <angle>, ]?
                [focus-distance <percentage>, ]?
                [center <point>, ]?
                radius [<length> | <percentage>],
                [[repeat | reflect],]?
                <color-stop>[, <color-stop>]+)
where
<point> = [ [ <length> <length> ] | [ <percentage> | <percentage> ] ]
<color-stop> = [ <color> [ <percentage> | <length>]? ]

Currently length can be only specified in px, the specification of unit can be omitted. Format of color representation is the one used in Color#web(String color). The radial-gradient keyword can be omitted. For additional information about the format of string representation, see the CSS Reference Guide.

Examples:
RadialGradient g
     = RadialGradient.valueOf("radial-gradient(center 100px 100px, radius 200px, red  0%, blue 30%, black 100%)");
RadialGradient g
     = RadialGradient.valueOf("center 100px 100px, radius 200px, red  0%, blue 30%, black 100%");
RadialGradient g
     = RadialGradient.valueOf("radial-gradient(center 50% 50%, radius 50%,  cyan, violet 75%, magenta)");
RadialGradient g
     = RadialGradient.valueOf("center 50% 50%, radius 50%,  cyan, violet 75%, magenta");
Parameters
value:String

the string to convert

Returns:RadialGradient

a RadialGradient object holding the value represented by the string argument.

Exceptions
NullPointerException:
if the value is null
IllegalArgumentException:
if the value cannot be parsed
Since
JavaFX 2.1