简体   繁体   English

JavaFX8如何从左侧而不是从右侧设置标签的省略号?

[英]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.

相关问题 如何在右侧的标签中设置文本? - How to set text in a label on the right side? 错误解析变量和左侧分配并计算++令牌 - Error resolving variables and left-side side assignments and figuring ++ tokens 禁用ViewPager从右向左和从左向右滑动 - Disable ViewPager Swipe From Right To Left and Left To Right Side 从JavaFX 2.2到JavaFX8 - From JavaFX 2.2 to JavaFX8 赋值语句左侧的Java后缀增量运算符的语义是什么,为什么它们与右侧不同? - What are the semantics of java's postfix increment operator on the left side of an assignment statement and why do they differ from the right side? 带有Jointable的JPA OneToMany,删除链接将删除右侧对象 - JPA OneToMany with Jointable, deleting a link deletes right-side object 如何从结果内部/右侧获取条件/左侧定义的所有流口水变量的列表? - How to get a list of all drools variables defined in condition / left hand side from inside the consequence / right hand side? ListView JavaFX中交替行左侧和右侧的图像和文本 - Image & text in left and right side on alternate row in ListView JavaFX JFreeChart:如何将 Y 轴从左侧移动到右侧? - JFreeChart: how to move Y-axis from left to right hand side? 如何在 java 中创建从右到左的数字模式? - How can i create a numeric pattern that starts from right to left side in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM