Forum Stats

  • 3,873,841 Users
  • 2,266,617 Discussions


TextField css disabled style not applied when disabled in the code

1044511 Member Posts: 7
edited Jun 1, 2016 10:33AM in JavaFX 2.0 and Later

Hi all,

I have a problem with disabled Text Fields style in my project. I have my windows designed in fxmls. In the css I have the next code to make the appearance different of the original disabled text field:

.text-field:disabled {
  -fx-disabled-opacity: 1.0;
  -fx-background-color: #EBEBEB;
  -fx-text-fill: #555555;

So, when a Text Field is disabled into the fxml code, it shows this way:

<TextField fx:id="textTest" disable="true"


Instead, if I make it disabled in the code the appearance changes:



I'm looking for a solution that doesn't involve coding anything different, I mean, I'd really love to have a solution that could be made in the css file so I don't have to change something in soooo many places.

Edition 1:

I have used a workaround. It consists in extending the TextField to a new type TextFieldTest and adding:

this.disableProperty().addListener(new ChangeListener<Boolean>() {

  public void changed(ObservableValue<? extends Boolean> observable,
  Boolean oldValue, Boolean newValue) {

       setStyle("-fx-opacity: 1.0");

So everytime it changes the disabled property, it always puts again opacity to 1.0. Anyway, I would appreciate if anyone knew any solution applied only to the css.

Mensaje editado por: 1044511 Edited to add the workaround

This discussion has been closed.