rbs
rbs

Reputation: 1167

How to change the size of the font of a Label to take the maximum size

I have a Label in a Scene. I need to get always the largest font size for the text in it, so that the text always takes the maximum size in the available size of the label.

How can I do that?

Upvotes: 7

Views: 31631

Answers (2)

Bhupen
Bhupen

Reputation: 1320

I am not sure if we have a way to set font size according to the size of the container. But you could scale the text vertically or horizontally to fit the container bounds. Check out the following ...

Scaling a textbox without truncating text within it

Upvotes: 2

invariant
invariant

Reputation: 8900

final double MAX_FONT_SIZE = 30.0; // define max font size you need
label.setFont(new Font(MAX_FONT_SIZE)); // set to Label

Upvotes: 10

Related Questions