APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt

public Class GradientPaint

extends Object
implements Paint
Class Inheritance
All Implemented Interfaces
java.awt.Paint, java.awt.Transparency
Imports
java.awt.geom.Point2D, .Rectangle2D, .AffineTransform, java.awt.image.ColorModel, java.beans.ConstructorProperties

The GradientPaint class provides a way to fill a Shape with a linear color gradient pattern. If Point P1 with Color C1 and Point P2 with Color C2 are specified in user space, the Color on the P1, P2 connecting line is proportionally changed from C1 to C2. Any point P not on the extended P1, P2 connecting line has the color of the point P' that is the perpendicular projection of P on the extended P1, P2 connecting line. Points on the extended line outside of the P1, P2 segment can be colored in one of two ways.
Version
10 Feb 1997
See Also
Paint, Graphics2D#setPaint

Field Summary

Modifier and TypeField and Description
pack-priv Color
pack-priv Color
pack-priv boolean
pack-priv Point2D.Float
pack-priv Point2D.Float

Constructor Summary

AccessConstructor and Description
public
GradientPaint(float
x coordinate of the first specified Point in user space
x1
,
float
y coordinate of the first specified Point in user space
y1
,
Color
Color at the first specified Point
color1
,
float
x coordinate of the second specified Point in user space
x2
,
float
y coordinate of the second specified Point in user space
y2
,
Color
Color at the second specified Point
color2
)

Constructs a simple acyclic GradientPaint object.

public
GradientPaint(Point2D
the first specified Point in user space
pt1
,
Color
Color at the first specified Point
color1
,
Point2D
the second specified Point in user space
pt2
,
Color
Color at the second specified Point
color2
)

Constructs a simple acyclic GradientPaint object.

public
GradientPaint(float
x coordinate of the first specified Point in user space
x1
,
float
y coordinate of the first specified Point in user space
y1
,
Color
Color at the first specified Point
color1
,
float
x coordinate of the second specified Point in user space
x2
,
float
y coordinate of the second specified Point in user space
y2
,
Color
Color at the second specified Point
color2
,
boolean
true if the gradient pattern should cycle repeatedly between the two colors; false otherwise
cyclic
)

Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

public
GradientPaint(Point2D
the first specified Point in user space
pt1
,
Color
Color at the first specified Point
color1
,
Point2D
the second specified Point in user space
pt2
,
Color
Color at the second specified Point
color2
,
boolean
true if the gradient pattern should cycle repeatedly between the two colors; false otherwise
cyclic
)

Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

Method Summary

Modifier and TypeMethod and Description
public PaintContext

Returns:

the PaintContext for generating color patterns.
createContext
(ColorModel
the preferred ColorModel which represents the most convenient format for the caller to receive the pixel data, or null if there is no preference.
cm
,
Rectangle
the device space bounding box of the graphics primitive being rendered.
deviceBounds
,
Rectangle2D
the user space bounding box of the graphics primitive being rendered.
userBounds
,
AffineTransform
the AffineTransform from user space into device space.
xform
,
RenderingHints
the set of hints that the context object can use to choose between rendering alternatives.
hints
)

Implements java.awt.Paint.createContext.

Creates and returns a PaintContext used to generate a linear color gradient pattern.

public Color

Returns:

a Color object that is the color anchored by P1.
getColor1
()

Returns the color C1 anchored by the point P1.

public Color

Returns:

a Color object that is the color anchored by P2.
getColor2
()

Returns the color C2 anchored by the point P2.

public Point2D

Returns:

a Point2D object that is a copy of the point that anchors the first color of this GradientPaint.
getPoint1
()

Returns a copy of the point P1 that anchors the first color.

public Point2D

Returns:

a Point2D object that is a copy of the point that anchors the second color of this GradientPaint.
getPoint2
()

Returns a copy of the point P2 which anchors the second color.

public int

Returns:

an integer value representing this GradientPaint object's transparency mode.
getTransparency
()

Implements java.awt.Transparency.getTransparency.

Returns the transparency mode for this GradientPaint.

public boolean

Returns:

true if the gradient cycles repeatedly between the two colors; false otherwise.
isCyclic
()

Returns true if the gradient cycles repeatedly between the two colors C1 and C2.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

color1back to summary
pack-priv Color color1
color2back to summary
pack-priv Color color2
cyclicback to summary
pack-priv boolean cyclic
p1back to summary
pack-priv Point2D.Float p1
p2back to summary
pack-priv Point2D.Float p2

Constructor Detail

GradientPaintback to summary
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)

Constructs a simple acyclic GradientPaint object.

Parameters
x1:float

x coordinate of the first specified Point in user space

y1:float

y coordinate of the first specified Point in user space

color1:Color

Color at the first specified Point

x2:float

x coordinate of the second specified Point in user space

y2:float

y coordinate of the second specified Point in user space

color2:Color

Color at the second specified Point

Exceptions
NullPointerException:
if either one of colors is null
GradientPaintback to summary
public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2)

Constructs a simple acyclic GradientPaint object.

Parameters
pt1:Point2D

the first specified Point in user space

color1:Color

Color at the first specified Point

pt2:Point2D

the second specified Point in user space

color2:Color

Color at the second specified Point

Exceptions
NullPointerException:
if either one of colors or points is null
GradientPaintback to summary
public GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic)

Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

Parameters
x1:float

x coordinate of the first specified Point in user space

y1:float

y coordinate of the first specified Point in user space

color1:Color

Color at the first specified Point

x2:float

x coordinate of the second specified Point in user space

y2:float

y coordinate of the second specified Point in user space

color2:Color

Color at the second specified Point

cyclic:boolean

true if the gradient pattern should cycle repeatedly between the two colors; false otherwise

GradientPaintback to summary
public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2, boolean cyclic)

Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

Parameters
pt1:Point2D

the first specified Point in user space

color1:Color

Color at the first specified Point

pt2:Point2D

the second specified Point in user space

color2:Color

Color at the second specified Point

cyclic:boolean

true if the gradient pattern should cycle repeatedly between the two colors; false otherwise

Annotations
@ConstructorProperties:point1, color1, point2, color2, cyclic
Exceptions
NullPointerException:
if either one of colors or points is null

Method Detail

createContextback to summary
public PaintContext createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)

Implements java.awt.Paint.createContext.

Creates and returns a PaintContext used to generate a linear color gradient pattern. See the specification of the method in the Paint interface for information on null parameter handling.

Parameters
cm:ColorModel

the preferred ColorModel which represents the most convenient format for the caller to receive the pixel data, or null if there is no preference.

deviceBounds:Rectangle

the device space bounding box of the graphics primitive being rendered.

userBounds:Rectangle2D

the user space bounding box of the graphics primitive being rendered.

xform:AffineTransform

the AffineTransform from user space into device space.

hints:RenderingHints

the set of hints that the context object can use to choose between rendering alternatives.

Returns:PaintContext

the PaintContext for generating color patterns.

See Also
Paint, PaintContext, ColorModel, Rectangle, Rectangle2D, AffineTransform, RenderingHints
getColor1back to summary
public Color getColor1()

Returns the color C1 anchored by the point P1.

Returns:Color

a Color object that is the color anchored by P1.

getColor2back to summary
public Color getColor2()

Returns the color C2 anchored by the point P2.

Returns:Color

a Color object that is the color anchored by P2.

getPoint1back to summary
public Point2D getPoint1()

Returns a copy of the point P1 that anchors the first color.

Returns:Point2D

a Point2D object that is a copy of the point that anchors the first color of this GradientPaint.

getPoint2back to summary
public Point2D getPoint2()

Returns a copy of the point P2 which anchors the second color.

Returns:Point2D

a Point2D object that is a copy of the point that anchors the second color of this GradientPaint.

getTransparencyback to summary
public int getTransparency()

Implements java.awt.Transparency.getTransparency.

Returns the transparency mode for this GradientPaint.

Returns:int

an integer value representing this GradientPaint object's transparency mode.

See Also
Transparency
isCyclicback to summary
public boolean isCyclic()

Returns true if the gradient cycles repeatedly between the two colors C1 and C2.

Returns:boolean

true if the gradient cycles repeatedly between the two colors; false otherwise.