Here you can find the source of toHexString(java.awt.Color colour)
public final static String toHexString(java.awt.Color colour) throws NullPointerException
//package com.java2s; //License from project: Apache License public class Main { public final static String toHexString(java.awt.Color colour) throws NullPointerException { String hexColour = Integer.toHexString(colour.getRGB() & 0xffffff); if (hexColour.length() < 6) { hexColour = "000000".substring(0, 6 - hexColour.length()) + hexColour; }//from w w w . j av a 2 s . c o m return "#" + hexColour; } }