fill Gradient Rectangle - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

fill Gradient Rectangle

Demo Code


//package com.java2s;
import java.awt.Color;

import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;

import java.awt.Paint;

public class Main {
    public static void fillGradientRect(Graphics2D offLineBuffer,
            Color startColor, Color endColor, int x, int y, int width,
            int height) {
        Paint prevPaint = offLineBuffer.getPaint();
        GradientPaint gradPaint = new GradientPaint(x, y, startColor, x, y
                + height, endColor, true);
        offLineBuffer.setPaint(gradPaint);
        offLineBuffer.fillRect(x, y, width, height);

        offLineBuffer.setPaint(prevPaint);
    }//from ww w .j a  v a 2  s  .  c  o m

    public static void fillRect(Graphics offLineBuffer, Color color, int x,
            int y, int width, int height) {
        offLineBuffer.setColor(color);
        offLineBuffer.fillRect(x, y, width, height);
    }
}

Related Tutorials