Java Hex to Color hexToColor(String hex)

Here you can find the source of hexToColor(String hex)

Description

hex To Color

License

Open Source License

Declaration

public static Color hexToColor(String hex) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;

public class Main {
    public static Color hexToColor(String hex) {

        hex = hex.replace("#", "");

        if (hex.length() == 6) {
            int r = Integer.valueOf(hex.substring(0, 2), 16);
            int g = Integer.valueOf(hex.substring(2, 4), 16);
            int b = Integer.valueOf(hex.substring(4, 6), 16);
            return new Color(r, g, b);
        }/*w w w .  ja  v  a  2 s.c om*/

        return Color.BLACK;

    }
}

Related

  1. hexToColor(final String hex)
  2. hexToColor(String color)
  3. hexToColor(String color)
  4. hexToColor(String colorHex)
  5. hexToColor(String hexStr, boolean throwException, int[] buffer)
  6. hexToColor(String hexString)
  7. hexToColor(String hexString)
  8. hexToColor(String input)