Here you can find the source of toHex(Color color)
public static String toHex(Color color)
//package com.java2s; //License from project: Open Source License import java.awt.*; public class Main { public static String toHex(Color color) { String alpha = pad(Integer.toHexString(color.getAlpha())); String red = pad(Integer.toHexString(color.getRed())); String green = pad(Integer.toHexString(color.getGreen())); String blue = pad(Integer.toHexString(color.getBlue())); return "#" + red + green + blue + alpha; //return Integer.parseInt(hex, 16); }/*from w ww .jav a 2 s . co m*/ private static String pad(String s) { return (s.length() == 1) ? "0" + s : s; } }