Java Color from String webColorCodeToJava(String value)

Here you can find the source of webColorCodeToJava(String value)

Description

web Color Code To Java

License

Open Source License

Declaration

public static Color webColorCodeToJava(String value) 

Method Source Code

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

public class Main {
    public static Color webColorCodeToJava(String value) {
        if (value.startsWith("#")) {
            value = value.substring(1);//from ww w . j ava 2s . co m
            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;
    }
}

Related

  1. stringToColor(String s)
  2. stringToColor(String s)
  3. stringToColor(String s)
  4. stringToColor(String s, boolean nullIfInvalid)
  5. stringToColorNoDefault(String string)