Here you can find the source of verticalGradient(BufferedImage image, Graphics2D g2d, Color... colors)
public static void verticalGradient(BufferedImage image, Graphics2D g2d, Color... colors)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.Point; import java.awt.geom.Point2D; import java.awt.image.BufferedImage; public class Main { public static void verticalGradient(BufferedImage image, Graphics2D g2d, Color... colors) { int miniHeight = image.getHeight() / (colors.length - 1); for (int i = 1; i < colors.length; i++) { Point start = new Point(0, (i - 1) * miniHeight); Point end = new Point(0, i * miniHeight); gradientPaint(g2d, start, colors[i - 1], end, colors[i], start.x, start.y, image.getWidth(), end.y); }//from w w w . jav a 2 s. com } public static void gradientPaint(Graphics2D g2d, Point2D startPosition, Color startColor, Point2D endPosition, Color endColor, int sx, int sy, int ex, int ey) { GradientPaint gradient = new GradientPaint(startPosition, startColor, endPosition, endColor, true); g2d.setPaint(gradient); g2d.fillRect(sx, sy, ex, ey); } }