简体   繁体   中英

Set JLabel Alignment right-left

I have a JPanel that separated to 2 blocks, in south block (layout) I have add a JLabel, In the label I want to Insert a string with this rule: (Name, Date, Time, In/Out)

If my name was written in English everything was fine the problem appeared when I wrote the name in some Unicode language like Farsi, then the alignment not working as expected. I attach 2 sample:

Right one: 在此输入图像描述

Wrong one: 在此输入图像描述

You can create two different labels next to each other. One for the name and one for the remaining part. This way, the alignment of the name label won't affect the alignment of the other label.

尝试在标签上使用Component.setComponentOrientation()来强制它从左到右的顺序。

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