Here you can find the source of linearGradient(final JComponent comp, final Color col, final int step, final int sleepTime)
public static SwingWorker<Void, Void> linearGradient(final JComponent comp, final Color col, final int step, final int sleepTime)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import javax.swing.JComponent; import javax.swing.SwingWorker; public class Main { public static SwingWorker<Void, Void> linearGradient(final JComponent comp, final Color col, final int step, final int sleepTime) { final Color cCol = comp.getBackground(); SwingWorker<Void, Void> colorThread = new SwingWorker<Void, Void>() { @Override//ww w . java 2 s .co m protected Void doInBackground() throws Exception { int cR = cCol.getRed(); int cG = cCol.getGreen(); int cB = cCol.getBlue(); int R = col.getRed(); int G = col.getGreen(); int B = col.getBlue(); int stepR = (R - cR) / step; int stepG = (G - cG) / step; int stepB = (B - cB) / step; for (int i = 0; i < step; i++) { cR += stepR; cG += stepG; cB += stepB; if (i < step / 2) Thread.sleep(sleepTime); else Thread.sleep(sleepTime / 2); comp.setBackground(new Color(cR, cG, cB)); } return null; } }; return colorThread; } }