Javafx - get RGB value from Node fill color

In my javafx application, I create a circle and then allow the user its color ...

Circle circle = new Circle(); circle.setFill(colorPicker.getValue()); 

Then I need to later select the color the circle is in and get the RGB values ​​in hexadecimal (#FFFFFF)

 circle.getFill(); //returns a Paint object 

How to get RGB hex fill?

+7
java colors javafx rgb paint
source share
1 answer

Try the following:

 Color c = (Color) circle.getFill(); String hex = String.format( "#%02X%02X%02X", (int)( c.getRed() * 255 ), (int)( c.getGreen() * 255 ), (int)( c.getBlue() * 255 ) ); 

Hope this helps.

+11
source share

All Articles