How to reduce the font of the text in the label below it is fully visible in the label in Java?

Application on JavaFX.
There is a label and textarea. The text is taken from a textarea and put in the label. The label will be constantly changing the text. When the text does not fit in the end of the sentence are 3 points that says that then comes the continuation of the text.

How to make the font size of the text adapted so that the text is always fully fit in the label?

I found this method, I measure the text from the textarea and set the condition if the text is longer than 500 characters, then change the font size of the label size(the size set in pixels)
String fontSmall ="-fx-font-size: 10px;"
 +"-fx-font-family: 'HeronSansCond SemiBold';"
 + "-fx-background-color: #fff;";

@FXML private TextArea ta_questText;

int str = ta_questText.getText().length();

cont.getLb_previewCard().textProperty().bind(ta_questText.textProperty());

if (str >= 500) {
cont.getLb_previewCard().setStyle(fontSmall);

 }


Here is a great disadvantage if the text is less than 500 and more ,such as 200, it will be wigdet small.
Is there a way to set the font size change as something different?
March 23rd 20 at 19:33
0 answer

Find more questions by tags JavaFXJava