Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get hex web String from JavaFX ColorPicker color?

I have Color chosen in JavaFX ColorPicker. Now I need to save it as hex string. I found this method, but for JavaFX it is not applicable. JavaFX has its own Color class without getRGB() method, that could be used as mediatory convertion.

like image 943
Zon Avatar asked Jul 29 '13 13:07

Zon


1 Answers

Translate a color into a web color code:

public class FxUtils
{
    public static String toRGBCode( Color color )
    {
        return String.format( "#%02X%02X%02X",
            (int)( color.getRed() * 255 ),
            (int)( color.getGreen() * 255 ),
            (int)( color.getBlue() * 255 ) );
    }
}
like image 148
Moe Avatar answered Nov 08 '22 11:11

Moe