简体   繁体   English

如何在javafx中对齐包裹文本

[英]How to right justify wrapped text in javafx

I have a JavaFX label that contains text that wraps. 我有一个JavaFX标签,其中包含自动换行的文本。 When the text wraps it shows like this: 文字换行时显示如下:

This is long text 
wrapping

I want it to wrap like this: 我希望它像这样包装:

This is long text 
         wrapping

So it will be aligned to the right. 因此它将向右对齐。 How do I do that?? 我怎么做??

I've tried this but with no success: 我已经尝试过,但是没有成功:

Label label = new Label();
label.setAlignment(Pos.CENTER_RIGHT);   
label.setWrapText(true);

setAlignment controls the overall alignment of the entire content of the label (all the text "as a block", plus the graphic) in the case where there is extra space in the label itself (ie where the size of the label is larger than its computed size). setAlignment标签本身有多余的空间(即标签的大小大于标签的大小),则setAlignment控制标签的整个内容的整体对齐方式(所有文本均为“块”,再加上图形)计算的大小)。

To control the alignment of individual lines of text in a multiline label, you can use setTextAlignment : 要控制多行标签中单个文本行的对齐方式,可以使用setTextAlignment

label.setTextAlignment(TextAlignment.RIGHT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM