Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback, please email oracle-forums_moderators_us@oracle.com

TextField css disabled style not applied when disabled in the code

1044511Jun 1 2016 — edited Jun 1 2016

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"

Captura.PNG

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

textTest.setDisabled(true);

Captura2.PNG

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>() {

  @Override

  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

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 29 2016
Added on Jun 1 2016
0 comments
562 views