Neil
Neil

Reputation: 6039

JavaFx 8 - Changing CSS style property values at runtime

I have to scale/change by button's text size dynamically whose default values are in CSS

.button { 
    -fx-font-size: 20;        
}

in JavaFx

button.getStyleClass().add("button");

Now I have to scale the fonts by factor 2 but there is no way to find the existing font size so that I could just multiply the factor

button.setStyle("-fx-font-size:"+oldVal*2);

How do I get the existing font size ?

Upvotes: 0

Views: 914

Answers (1)

Roland
Roland

Reputation: 18415

It's as easy as using

button.getFont().getSize();

It works only after the stage was shown.

Upvotes: 1

Related Questions