Skip to content
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
Cannot retrieve contributors at this time

PRs Welcome License Build Status Javadocs

AWT Color Factory

💡 You can use this library regardless of the license under which your software is distributed.

In JavaFX you can easily create a javafx.scene.paint.Color object from a string representation such as "lightblue", "#aa38e0", or "0x40A8CC" by using Color.web(String colorString), Color.web(String colorString, double opacity), or Color.valueOf(String value).

This one-class project provides equivalent methods for creating java.awt.Color objects.

Example usage

Color c1 = ColorFactory.valueOf("firebrick");
Color c2 = ColorFactory.valueOf("#aa38e0");
Color c3 = ColorFactory.valueOf("0x40A8CC");
Color c4 = ColorFactory.valueOf("rgba(112,36,228,0.9)");
Color c5 = ColorFactory.web("forestgreen", 0.7);
Color c6 = ColorFactory.web("hsl(270,90%,70%)", 0.8);

See the javadoc for more details.

Why should you use this library? Can't you just call the JavaFX methods and convert the returned javafx.scene.paint.Color into a java.awt.Color? Of course you can. But you may find this little library useful if you don't want your code to depend on JavaFX. And remember, starting with JDK 11, JavaFX is no longer part of the JDK.

AWT Color Factory is available in JCenter and Maven Central.




compile 'org.beryx:awt-color-factory:1.0.1'

AWT Color Factory contains code that is almost identical to that found in javafx.scene.paint.Color, therefore the library is distributed under the same license as OpenJFX: the GPL 2 with Classpath exception. The Classpath exception clause gives you permission to include this library in your executable code, regardless of the license under which your software is distributed.

This library requires Java 7 or newer. The jar artifact is modularized under the name org.beryx.awt.color.