How to change the color of pane in javafx?

maryam picture maryam · Apr 3, 2014 · Viewed 53.8k times · Source

I want to change the color of a Pane which I get as a String from user. How can I set this String as a background color in my pane?

Code:

colorField.setOnKeyTyped(new EventHandler<KeyEvent>() {
    @Override
    public void handle(KeyEvent t) {
        color = colorField.getText();
    }
});

Answer

int lawl is over 9000 picture int lawl is over 9000 · Apr 4, 2014

If you really just want to know how to accomplish that particular thing, I'd suggest the following:

Set the Nodes' CSS like this, using the hexacolor that was entered by the user:

String enteredByUser = "abcdef";
yournode.setStyle("-fx-background-color: #" + enteredByUser);

If you want to know more please be more specific with you questions and provide some code samples.

Since you tagged this question with 'javafx-8' i'll provide that code example as well(only works in javafx 8):

yournode.setBackground(new Background(new BackgroundFill(Color.web("#" + enteredByUser), CornerRadii.EMPTY, Insets.EMPTY)));

Hope it helps, Laurenz