0

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 ?

1 Answer 1

1

It's as easy as using

button.getFont().getSize();

It works only after the stage was shown.

Sign up to request clarification or add additional context in comments.

3 Comments

Accepted and upvoted . it works for me now. However I was looking for a generic solution where I can multiply the factor in the style even before setting it for the first time.
You could parse the stylesheet but with all the inheritance that might be going on I rather advise against it.
I know, I could do a getStyle() and look for the string separated by ";" and containing the style name but that sounds fragile.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.