简体   繁体   English

将JLabel Alignment设置为左右

[英]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) 我有一个分隔为2个块的JPanel,在南块(布局)中我添加了一个JLabel,在标签中我想插入一个带有此规则的字符串:( (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. 如果我的名字是用英文写的,那么当我用像波斯语这样的Unicode语言编写名称时,一切都很好,然后对齐不按预期工作。 I attach 2 sample: 我附上2个样本:

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()来强制它从左到右的顺序。

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

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