Class ColorParser


  • public final class ColorParser
    extends java.lang.Object
    Parses colors from text strings. Supports formats:
    • #F00
    • #FFAABB
    • rgb(100,100,100)
    • rgba(100,100,100, 100)
    • hsl(100,100,100)
    • hsla(100,100,100, 100)
    • -65536
    • red
    The numbers in the rgb(..) and hsl(..) can have the following formats:
    • 0-255
    • 0%-100%
    • 0.0%-100.0%
    • 0.0-1.0
    • 0f-1f
    • 0.0f-1.0f
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean canParseColor​(java.lang.String colorString)
      Check if the given color string can be parsed.
      static java.awt.Color toColor​(java.lang.String colorString)
      Parse the string and convert it to a Color.
      static java.lang.String toRGB​(java.awt.Color color)
      Get the "rgb(...)" representation for a color.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toColor

        public static java.awt.Color toColor​(java.lang.String colorString)
        Parse the string and convert it to a Color. See class description for details on the supported color formats.
        Parameters:
        colorString - the color string encoded.
        Returns:
        Always return a Color or an exception
        Throws:
        java.lang.NumberFormatException - when the colorString cannot be parsed
      • canParseColor

        public static boolean canParseColor​(java.lang.String colorString)
        Check if the given color string can be parsed.
        Parameters:
        colorString - The color to parse.
      • toRGB

        public static java.lang.String toRGB​(java.awt.Color color)
        Get the "rgb(...)" representation for a color.
        Parameters:
        color - The color.