I have a TextArea
in my JavaFX program that I want to be able to allow the user to set the background color of. I was able to figure out how to change the background color using an external css
file by doing this.
.text-area .content {
-fx-background-color: blue ;
}
However, this would only allow me to have a default setting and the user would not be able to select a color from a menu to change it.
I also tried doing this in Java code.
textArea.setStyle("-fx-background-color: green");
But it doesn't change anything because the TextArea
has more depth to it.
Is there any way I can change the background multiple times without having to modify the css
file?
Use the external CSS file to define the background color using a looked-up color (scroll down the link to just below all the color swatches):
(Here
text-area-background
is essentially an arbitrary variable name of your choosing.)Then you can programmatically update the definition of the looked-up-color:
Here's an SSCCE:
With the css file text-area-background.css: