Here you can find the source of toHexString(Color color)
Parameter | Description |
---|---|
color | the color |
null
public static final String toHexString(Color color)
//package com.java2s; import java.awt.Color; public class Main { /**/*from w w w . ja v a2 s .co m*/ * Converts a color to its hex representation (0xFFFFFF). * * @param color * the color * @return String its string representation or <code>null</code> */ public static final String toHexString(Color color) { if (color == null) { return null; } StringBuilder str = new StringBuilder("0x"); if (color.getRed() < 16) { str.append('0'); } str.append(Integer.toHexString(color.getRed())); if (color.getGreen() < 16) { str.append('0'); } str.append(Integer.toHexString(color.getGreen())); if (color.getBlue() < 16) { str.append('0'); } str.append(Integer.toHexString(color.getBlue())); return str.toString(); } }