Java Color from String stringToColor(String colorString)

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

Description

string To Color

License

BSD License

Declaration

public static java.awt.Color stringToColor(String colorString) 

Method Source Code


//package com.java2s;
//License from project: BSD License 

import java.awt.Color;

public class Main {
    public static java.awt.Color stringToColor(String colorString) {
        try {/* w  w  w .  j av  a2s .  c  om*/
            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);
        } catch (NumberFormatException nfe) {
            //unrecognized
            return null;
        }
    }
}

Related

  1. stringToColor(final String s)
  2. stringToColor(final String value)
  3. stringToColor(String color)
  4. stringToColor(String color)
  5. stringToColor(String colorName)
  6. StringToColor(String name)
  7. stringToColor(String s)
  8. stringToColor(String s)
  9. stringToColor(String s)