Here you can find the source of toHexString(java.awt.Color c)
Parameter | Description |
---|---|
c | color |
public static String toHexString(java.awt.Color c)
//package com.java2s; public class Main { /**/*from w w w . j a v a2 s. c om*/ * Convert the given color to is string hex representation * * @param c color * @return hex represenation */ public static String toHexString(java.awt.Color c) { return "#" + padRight(Integer.toHexString(c.getRed()), 2, "0") + padRight(Integer.toHexString(c.getGreen()), 2, "0") + padRight(Integer.toHexString(c.getBlue()), 2, "0"); } /** * Pad the given string with spaces on the right up to the given length. * * @param s String to pad * @param desiredLength ending length * @return padded String */ public static String padRight(String s, int desiredLength) { return padRight(s, desiredLength, " "); } /** * Pad the given string with padString on the right up to the given length. * * @param s String to pad * @param desiredLength ending length * @param padString String to pad with (e.g, " ") * @return padded String */ public static String padRight(String s, int desiredLength, String padString) { while (s.length() < desiredLength) { s = s + padString; } return s; } }