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

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

Upvotes: 1

Views: 2137

Answers (1)

jewelsea
jewelsea

Reputation: 159416

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();

Upvotes: 2

Related Questions