How can i convert color picker value to a web or rgb or any Color class compatible type?

1

My color picker in javaFX returns something like 0x000000ff. How to convert this to web colors, either rgb or hex?

javafx
colors
rgb
graphicscontext
asked on Stack Overflow Jan 22, 2016 by እስኬንድር ተናግረኁ • edited Jan 22, 2016 by Minderov

1 Answer

2

The answer to this for rgb values is right in the javadoc for ColorPicker:

final ColorPicker colorPicker = new ColorPicker();
colorPicker.setOnAction(new EventHandler() {
    public void handle(Event t) {
        Color c = colorPicker.getValue();
        System.out.println("New Color's RGB = "+c.getRed()+" "+c.getGreen()+" "+c.getBlue());
    }
});

Or you can get the color as a hex string for the above sample using:

String hexString = c.toString();
answered on Stack Overflow Jan 22, 2016 by jewelsea

User contributions licensed under CC BY-SA 3.0