Java Utililty Methods Color from String

List of utility methods to do Color from String

Description

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

Method

ColorstringToColor(String s)
string To Color
int iColor = Integer.parseInt(s);
return new Color(iColor);
ColorstringToColor(String s)
string To Color
try {
    return new Color(Integer.decode("0x" + s.substring(1, 3)).intValue(),
            Integer.decode("0x" + s.substring(3, 5)).intValue(),
            Integer.decode("0x" + s.substring(5, 7)).intValue());
} catch (Exception e) {
    throw new IllegalArgumentException("Bad color string format. Should be #rrggbb ");
ColorstringToColor(String s)
string To Color
if (s.startsWith("[")) {
    s = s.substring(1);
if (s.endsWith("]")) {
    s = s.substring(0, s.length() - 1);
int i = 0;
int red = 0;
...
ColorstringToColor(String s, boolean nullIfInvalid)
string To Color
try {
    return new Color(Integer.parseInt(s, 16));
} catch (Exception e) {
    return nullIfInvalid ? null : Color.WHITE;
ColorstringToColorNoDefault(String string)
string To Color No Default
string = string.replace("\"", "").replace("'", "");
Color c = null;
if (string.contains(",")) {
    String[] rgb = string.split(",");
    int red = Integer.parseInt(rgb[0]);
    int green = Integer.parseInt(rgb[1]);
    int blue = Integer.parseInt(rgb[2]);
    c = new Color(red, green, blue);
...
ColorwebColorCodeToJava(String value)
web Color Code To Java
if (value.startsWith("#")) {
    value = value.substring(1);
    int red = Integer.parseInt(value.substring(0, 2), 16);
    int green = Integer.parseInt(value.substring(2, 4), 16);
    int blue = Integer.parseInt(value.substring(4, 6), 16);
    return new Color(red, green, blue);
return Color.WHITE;
...