简体   繁体   中英

How to right justify wrapped text in javafx

I have a JavaFX label that contains text that wraps. 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).

To control the alignment of individual lines of text in a multiline label, you can use setTextAlignment :

label.setTextAlignment(TextAlignment.RIGHT);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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