Here you can find the source of getDarkerColor(Color color)
Parameter | Description |
---|---|
color | The color to make darker |
public static Color getDarkerColor(Color color)
//package com.java2s; import java.awt.Color; public class Main { private static final double DARKER_SCALE = 0.95; private static final int MINVALUE = 0; private static final int MAXVALUE = 255; /**//w w w . java 2s .c o m * * @param color The color to make darker * @return The darker color */ public static Color getDarkerColor(Color color) { return getScaledColor(color, DARKER_SCALE); } /** * * @param color The color to adjust * @param scaleFactor the amount to scale the colors by * @return The adjusted color */ public static Color getScaledColor(Color color, double scaleFactor) { return new Color(getScaledColorComponent(color.getRed(), scaleFactor), getScaledColorComponent(color.getGreen(), scaleFactor), getScaledColorComponent(color.getBlue(), scaleFactor)); } private static int getScaledColorComponent(int colorComponent, double scaleFactor) { int scaledValue = (int) (colorComponent * scaleFactor); if (scaledValue < MINVALUE) { scaledValue = MINVALUE; } else if (scaledValue > MAXVALUE) { scaledValue = MAXVALUE; } return scaledValue; } }