paint Gradient - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

paint Gradient

Demo Code


//package com.java2s;
import javax.swing.*;
import java.awt.*;

public class Main {
    static void paintGradient(JComponent c, Graphics g, Paint... paints) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        for (Paint paint : paints) {
            g2d.setPaint(paint);/*  w  ww . java  2  s  . co m*/
            g2d.fillRect(0, 0, c.getWidth(), c.getHeight());
        }
    }
}

Related Tutorials