Lidiia
Lidiia

Reputation: 1

Change color of label if mouse not on button

JavaFX So I have code where if mouse on button when color of label is changing

AeroportT1.hoverProperty().addListener((event)->tAeroportT1.setTextFill(Color.web("#ff0909")));

But I need change color back when mouse not on button.

Upvotes: 0

Views: 74

Answers (1)

Alex
Alex

Reputation: 866

You should use ChangeListener but not InvalidationListener for your purpose

AeroportT1.hoverProperty().addListener((observable, oldValue, newValue) -> 
         AeroportT1.setTextFill(newValue ? Color.RED : Color.BLUE));

Or you can use Bindings

AeroportT1.textFillProperty().bind(Bindings.when(AeroportT1.hoverProperty()).then(Color.RED).otherwise(Color.BLUE));

Upvotes: 4

Related Questions