Here you can find the source of toColor(final String hexString)
Parameter | Description |
---|---|
hexString | The hexadecimal string (with # prefix) to be translated to a color |
public static Color toColor(final String hexString)
//package com.java2s; import java.awt.Color; public class Main { /**/*from w w w .ja v a 2 s . c om*/ * In a lot of HTML documents and still others, colors are represented using the RGB values, concatenated as * hexadecimal strings. This function is used to create a color object from such a hexadecimal string. * * @param hexString The hexadecimal string (with # prefix) to be translated to a color * @return The color represented by this hexadecimal string */ public static Color toColor(final String hexString) { return new Color(Character.digit(hexString.charAt(1), 16) * 16 + Character.digit(hexString.charAt(2), 16), Character.digit(hexString.charAt(3), 16) * 16 + Character.digit(hexString.charAt(4), 16), Character.digit(hexString.charAt(5), 16) * 16 + Character.digit(hexString.charAt(6), 16)); } }