Example usage for java.awt GradientPaint createContext

List of usage examples for java.awt GradientPaint createContext

Introduction

In this page you can find the example usage for java.awt GradientPaint createContext.

Prototype

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

Source Link

Document

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

Usage

From source file:Main.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    gp1.createContext(ColorModel.getRGBdefault(), new Rectangle(0, 0, 30, 40), new Rectangle(0, 0, 30, 40),
            new AffineTransform(), null);

    System.out.println(gp1.getTransparency());
    g2d.setPaint(gp1);//from  w  w w  . j  av  a2  s .  c o  m
    g2d.fillRect(20, 20, 300, 40);

}