Module MaterialFX

Class ColorUtils

java.lang.Object
io.github.palexdev.materialfx.utils.ColorUtils

public class ColorUtils extends Object
Utils class for JavaFX's Colors and CSS.
  • Method Details

    • toCss

      public static String toCss(Paint paint)
      Converts a JavaFX Paint object to the right CSS string.

      Supports: Color, LinearGradient, RadialGradient.

    • rgb

      public static String rgb(Color color)
      Converts a JavaFX's Color to CSS corresponding rgb function.
      Returns:
      the rgb function as a string
    • rgba

      public static String rgba(Color color)
      Converts a JavaFX's Color to CSS corresponding rgba function.
      Returns:
      the rgba function as a string
    • getRandomColor

      public static Color getRandomColor()
      Generates a random Color using java.util.Random.
    • linearGradientToString

      public static String linearGradientToString(LinearGradient gradient)
      Util method to convert LinearGradient to a CSS string.

      This is partly a copy of LinearGradient.toString() but Stops are correctly converted for CSS.
      Parameters:
      gradient - the linear gradient to convert
      See Also:
    • radialGradientToString

      public static String radialGradientToString(RadialGradient gradient)
      Util method to convert RadialGradient to a CSS string.

      This is partly a copy of RadialGradient.toString() but Stops are correctly converted for CSS.
      Parameters:
      gradient - the radial gradient to convert
      See Also:
    • stopToString

      public static String stopToString(Stop stop)
      Properly converts a Stop to string. Partly copied from Stop.toString() but the color is converted using rgba(Color).
    • toWeb

      public static String toWeb(Color color)
      Converts the given color to a String in hexadecimal format.
    • toWebAlpha

      public static String toWebAlpha(Color color)
      Converts the given color to a String in hexadecimal format, also includes the color's opacity.
    • toHSL

      public static String toHSL(Color color)
      Converts the given color to a String in HSL format.
    • toHSB

      public static String toHSB(Color color)
      Converts the given color to a String in HSB format.