Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the color of pane in javafx?

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();
    }
});
like image 819
maryam Avatar asked Apr 03 '14 14:04

maryam


People also ask

How can I change background color of pane in JavaFX?

Set Background Color You can set a background color for a JavaFX Region like this: Pane pane = new Pane(); BackgroundFill backgroundFill = new BackgroundFill( Color. valueOf("#ff00ff"), new CornerRadii(10), new Insets(10) ); Background background = new Background(backgroundFill); pane. setBackground(background);

How do I change the stage color in JavaFX?

The simplest way to set the JavaFX Scene background color or image is by invoking the Scene 's setFill() method, which can accept a color, gradient or image pattern. A more flexible way to set the background of a scene is to set the root node's background, which can accept multiple images and fills.

What does pane do in JavaFX?

Pane provides properties for setting the size range directly. These properties default to the sentinel value Region.

Is a pane a node JavaFX?

A Pane is a UI element ("Node") that contains other UI elements ("child nodes") and manages the layout of those nodes within the Pane . There are several predefined Pane types (subclasses of Pane ) that differ in how they lay out their child nodes.


1 Answers

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

like image 87
int lawl is over 9000 Avatar answered Oct 12 '22 05:10

int lawl is over 9000