Answer the question
In order to leave comments, you need to log in
How to reduce the font of the text in the label so that it fits completely in the label in Java?
Application in JavaFX.
There is a label and a textarea. The text is taken from the textarea and inserted into the label. The label will constantly change the text. When the text does not fit, 3 dots remain at the end of the sentence, which indicates that the continuation of the text follows.
How can I make the font size of the text adapt so that the text always fits completely in the label?
I found this way, I measure the text from the textarea and set the condition, if the text is more than 500 characters, then I change the label font size to another size (I set the size 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);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question