This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


java.awt
class GradientPaint

java.lang.Object extended by java.awt.GradientPaint
All Implemented Interfaces:
Paint

Most common way to construct:

Color colorFrom = …;
int width = …;
int height = …;
Color colorTo = …;

GradientPaint paint = new GradientPaint(0, 0, colorFrom, width, height, colorTo);

Based on 7 examples


public class GradientPaint
extends Object
implements Paint

The GradientPaint class provides a way to fill a {@link Shape} with a linear color gradient pattern. If {@link Point} P1 with {@link 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.


Constructor Summary
GradientPaint(float x1, float y1, Color color1, float x2, float y2, Color color2)

          Constructs a simple acyclic GradientPaint object.
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.
GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2)

          Constructs a simple acyclic GradientPaint object.
GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2, boolean cyclic)

          Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.
 
Method Summary
 PaintContext
createContext(ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform xform, RenderingHints hints)

          Creates and returns a context used to generate the color pattern.
 Color

          Returns the color C1 anchored by the point P1.
 Color

          Returns the color C2 anchored by the point P2.
 Point2D

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

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

          Returns the transparency mode for this GradientPaint.
 boolean

          Returns true if the gradient cycles repeatedly between the two colors C1 and C2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GradientPaint

public GradientPaint(float x1,
                     float y1,
                     Color color1,
                     float x2,
                     float y2,
                     Color color2)
Constructs a simple acyclic GradientPaint object.

Parameters:
x1 - x coordinate of the first specified Point in user space
y1 - y coordinate of the first specified Point in user space
color1 - Color at the first specified Point
x2 - x coordinate of the second specified Point in user space
y2 - y coordinate of the second specified Point in user space
color2 - Color at the second specified Point

GradientPaint

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 - x coordinate of the first specified Point in user space
y1 - y coordinate of the first specified Point in user space
color1 - Color at the first specified Point
x2 - x coordinate of the second specified Point in user space
y2 - y coordinate of the second specified Point in user space
color2 - Color at the second specified Point
cyclic - true if the gradient pattern should cycle repeatedly between the two colors; false otherwise

GradientPaint

public GradientPaint(Point2D pt1,
                     Color color1,
                     Point2D pt2,
                     Color color2)
Constructs a simple acyclic GradientPaint object.

Parameters:
pt1 - the first specified Point in user space
color1 - Color at the first specified Point
pt2 - the second specified Point in user space
color2 - Color at the second specified Point

GradientPaint

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 - the first specified Point in user space
color1 - Color at the first specified Point
pt2 - the second specified Point in user space
color2 - Color at the second specified Point
cyclic - true if the gradient pattern should cycle repeatedly between the two colors; false otherwise
Method Detail

createContext

public PaintContext createContext(ColorModel cm,
                                  Rectangle deviceBounds,
                                  Rectangle2D userBounds,
                                  AffineTransform xform,
                                  RenderingHints hints)
Creates and returns a context used to generate the color pattern.

Parameters:
cm - {@link ColorModel} that receives the Paint data. This is used only as a hint.
deviceBounds - the device space bounding box of the graphics primitive being rendered
userBounds - the user space bounding box of the graphics primitive being rendered
xform - the {@link AffineTransform} from user space into device space
hints - the hints that the context object uses to choose between rendering alternatives
Returns:
the {@link PaintContext} that generates color patterns.

getColor1

public Color getColor1()
Returns the color C1 anchored by the point P1.

Returns:
a Color object that is the color anchored by P1.

getColor2

public Color getColor2()
Returns the color C2 anchored by the point P2.

Returns:
a Color object that is the color anchored by P2.

getPoint1

public Point2D getPoint1()
Returns a copy of the point P1 that anchors the first color.

Returns:
a {@link Point2D} object that is a copy of the point that anchors the first color of this GradientPaint.

getPoint2

public Point2D getPoint2()
Returns a copy of the point P2 which anchors the second color.

Returns:
a {@link Point2D} object that is a copy of the point that anchors the second color of this GradientPaint.

getTransparency

public int getTransparency()
Returns the transparency mode for this GradientPaint.

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

isCyclic

public boolean isCyclic()
Returns true if the gradient cycles repeatedly between the two colors C1 and C2.

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


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.