[英]JavaFX8 How to set a label's ellipsis from the left-side not from the right-side?
JavaFX 8 can auto ellipsisize Label's text started at the right side. JavaFX 8可以自动在右边开始省略Label的文本。 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. 在Android上,可以通过在XML文件中设置TextView的ellipsize属性来轻松实现,但是在JavaFX上,我不知道这样做。
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: 您也可以在FXML中执行此操作:
<Label text="Answer your own question" textOverrun="LEADING_ELLIPSIS"/>
or even in css: 甚至在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.) (后者将为所有标签设置文本溢出;如果要将ID仅应用于一个标签,则可以使用id作为选择器。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.