How do you change the background color of a TextField without changing the border in javafx?

sazzy4o picture sazzy4o · Dec 30, 2014 · Viewed 37.6k times · Source

I am trying to change the background color of my TextField "colorBox0" to "value0" but it gets rid of the border.
Here is a simplified version of my code:

   static Paint value0 = Paint.valueOf("FFFFFF");
   TextField colorBox0;
   colorBox0.setBackground(new Background(new BackgroundFill(value0, CornerRadii.EMPTY, Insets.EMPTY)));

Any help is very much appreciated
Thank you

Answer

sazzy4o picture sazzy4o · Dec 30, 2014

I found that you can construct a string of css code out of a string and a variable by using the to string method and the substring method like this:

colorBox0
.setStyle("-fx-control-inner-background: #"+value0.toString().substring(2));