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

Colorstr2Color(String s, Color defaultValue)
We have this method to convert the "standard" Color constants as a String to their Color value.
Color result = defaultValue;
if (s != null) {
    if (s.equalsIgnoreCase("BLACK")) {
        result = Color.BLACK;
    } else if (s.equalsIgnoreCase("BLUE")) {
        result = Color.BLUE;
    } else if (s.equalsIgnoreCase("CYAN")) {
        result = Color.CYAN;
...
java.awt.Colorstring2color(String str)
Insert the method's description here.
int rgb = Integer.parseInt(str);
switch (rgb) {
case 0x000000:
    return Color.black;
case 0x0000ff:
    return Color.blue;
case 0x00ff00:
    return Color.green;
...
Colorstring2Color(String stringColor)
Obtiene el color de un string generado con color2String
if (stringColor == null || stringColor.equals("null"))
    return null;
String[] ints = new String[4];
ints = stringColor.split(",");
int[] ret = new int[4];
for (int i = 0; i < ret.length; i++) {
    ret[i] = new Integer(ints[i]).intValue();
return new Color(ret[0], ret[1], ret[2], ret[3]);
ColorstringToColor(final String s)
Converts the given string into a Color object.
final int[] a = s == null ? null : stringToIntArray(s);
if (a == null || a.length < 3)
    return null;
if (a.length == 3)
    return new Color(a[0], a[1], a[2]);
return new Color(a[0], a[1], a[2], a[3]);
ColorstringToColor(final String value)
Converts a given string into a color.
if (value == null) {
    return Color.BLACK;
try {
    return Color.decode(value);
} catch (NumberFormatException nfe) {
    try {
        final Field f = Color.class.getField(value);
...
ColorstringToColor(String color)
string To Color
if (color == null) {
    return null;
int r = 0, g = 0, b = 0;
try {
    String tmpcolor = color.trim();
    tmpcolor = tmpcolor.substring(1, tmpcolor.length() - 1);
    String rgb[] = tmpcolor.split(",");
...
ColorstringToColor(String color)
string To Color
if (color == null)
    return null;
int r;
int g;
int b;
int ind1 = color.indexOf(',');
if (ind1 > 0) {
    r = Integer.parseInt(color.substring(0, ind1 - 1));
...
ColorstringToColor(String colorName)
string To Color
colorName = colorName.trim();
if (colorName.startsWith("#")) {
    if (colorName.length() != 7)
        throw new IllegalArgumentException("Invalid #RRGGBB sytnax: " + colorName);
    int r = Integer.parseInt(colorName.substring(1, 3), 16);
    int g = Integer.parseInt(colorName.substring(3, 5), 16);
    int b = Integer.parseInt(colorName.substring(5, 7), 16);
    return new Color(r, g, b);
...
java.awt.ColorstringToColor(String colorString)
string To Color
try {
    String colorClean;
    if (colorString.length() > 0 && colorString.charAt(0) == '#')
        colorClean = colorString.substring(1);
    else
        colorClean = colorString;
    int ncolor = Integer.parseInt(colorClean, 16);
    return new Color(ncolor);
...
ColorStringToColor(String name)
String To Color
Color new_color = null;
try {
    if (null != reverseColorsHashtable) {
        new_color = reverseColorsHashtable.get(name);
} catch (Exception e) {
    e.printStackTrace();
try {
    if (null == new_color) {
        new_color = Color.getColor(name);
} catch (Exception e) {
    e.printStackTrace();
return new_color;