Java Color from String stringToColor(String s)

Here you can find the source of stringToColor(String s)

Description

string To Color

License

Open Source License

Declaration

public static Color stringToColor(String s) 

Method Source Code


//package com.java2s;
import java.awt.Color;

public class Main {
    public static Color stringToColor(String s) {
        if (s.startsWith("[")) {
            s = s.substring(1);/*from   w  ww .  ja  v a 2 s  . com*/
        }
        if (s.endsWith("]")) {
            s = s.substring(0, s.length() - 1);
        }
        //        System.out.println(s);
        int i = 0;

        int red = 0;
        int green = 0;
        int blue = 0;

        for (String p : s.split(",")) {
            if (i == 0) {
                red = Integer.parseInt(p);
            } else if (i == 1) {
                green = Integer.parseInt(p);
            } else if (i == 2) {
                blue = Integer.parseInt(p);
            }
            i++;
        }
        return new Color(red, green, blue);
    }
}

Related

  1. stringToColor(String colorName)
  2. stringToColor(String colorString)
  3. StringToColor(String name)
  4. stringToColor(String s)
  5. stringToColor(String s)
  6. stringToColor(String s, boolean nullIfInvalid)
  7. stringToColorNoDefault(String string)
  8. webColorCodeToJava(String value)