Java Utililty Methods Color to HTML

List of utility methods to do Color to HTML

Description

The list of methods to do Color to HTML are organized into topic(s).

Method

ColorattemptHTML(String colour)
attempt HTML
return htmlColours.get(colour.toLowerCase());
StringcolourToHtmlString(Color colour)
Converts a Color to an HTML String (#RRGGBB), ignoring transparency.
if (colour == null) {
    return null;
return String.format("#%06X", colour.getRGB() & 0x00FFFFFF);
StringcovertToHtmlColor(Color color)
covert To Html Color
return color == null ? null
        : "#" + to2BitHexString(color.getRed()) + to2BitHexString(color.getGreen())
                + to2BitHexString(color.getBlue());
StringtoHTMLColor(Color c)
to HTML Color
return "#" + Integer.toHexString(c.getRGB()).substring(2);
StringtoHTMLColor(Color c)
Return the hexidecimal color from a java.awt.Color
int color = c.getRGB();
color |= 0xff000000;
String s = Integer.toHexString(color);
return s.substring(2);
StringtoHtmlColor(Color color)
Converts the color into a Hex representation suitable for HTML color attributes.
String rgb = Integer.toHexString(color.getRGB());
return "#" + rgb.substring(2, rgb.length());
StringtoHtmlColor(Color color)
Converts an integer to an HTML color representation.
String result = null;
if (color != null) {
    char[] cars = new char[7];
    cars[0] = '#';
    toHex((byte) color.getRed(), cars, 1); 
    toHex((byte) color.getGreen(), cars, 3); 
    toHex((byte) color.getBlue(), cars, 5); 
    return new String(cars);
...
StringtoHtmlHex(Color color)
to Html Hex
return String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue());
StringtoHtmlRGB(Color col)
to Html RGB
String r = Integer.toHexString(col.getRed());
String g = Integer.toHexString(col.getGreen());
String b = Integer.toHexString(col.getBlue());
return "#" + (r.length() == 1 ? "0" + r : r) + (g.length() == 1 ? "0" + g : g)
        + (b.length() == 1 ? "0" + b : b);
StringtoHtmlString(Color color)
Converts a color to a HTML color in the format #RRGGBB.
return String.format("#%06X", color.getRGB() & 0xffffff);