JavaFX 8 can auto ellipsisize Label's text started at the right side. For example, if there is a sentence 'Answer your own question', it may be ellipsisized to 'Answer your own que...' because there is no enough space to show the sentence completely.
But now, I want to ellipsize the left-side text, not the right-side. For example, if there is a sentence 'Answer your own question', I want to make it ellipsized to '...our own question'.
On Android, it can be easily implemented by setting the TextView's ellipsize attribute in a XML file, but on JavaFX, I have no idea to do that.
Use
label.setTextOverrun(OverrunStyle.LEADING_ELLIPSIS);
or
label.setTextOverrun(OverrunStyle.LEADING_WORD_ELLIPSIS);
depending on the exact behavior you want. (Documentation is here.)
You can also do this in FXML:
<Label text="Answer your own question" textOverrun="LEADING_ELLIPSIS"/>
or even in css:
.label {
-fx-text-overrun: leading-ellipsis ;
}
(The latter will set the text overrun for all labels; you can use an id as the selector if you want to apply it to just one label.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With