Paints a horizontal gradient background from the start color to the end color. - Java 2D Graphics

Java examples for 2D Graphics:Color Blend

Description

Paints a horizontal gradient background from the start color to the end color.

Demo Code


//package com.java2s;
import java.awt.Graphics2D;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Image;

public class Main {
    /**//w  w w .j a  va2  s .  co m
     * Paints a horizontal gradient background from the start color to the end color.
     */
    public static void paintHorizontalGradient(Image image, int x, int y,
            int w, int h, int width, Color startColor, Color endColor) {
        Graphics2D g2 = (Graphics2D) image.getGraphics();
        g2.setPaint(new GradientPaint(x, 0, startColor, width, 0, endColor));
        g2.fillRect(x, y, w, h);
        g2.dispose();
    }
}

Related Tutorials