设置 JLabel 左右对齐
我有一个 JPanel,分为 2 个块,在南块(布局)中我添加了一个 JLabel,在标签中我想插入一个具有以下规则的字符串: (Name, Date, Time, In/Out)< /code>
如果我的名字是用英语写的,一切都很好,但当我用波斯语等 Unicode 语言写名字时,问题就出现了,然后对齐方式无法按预期工作。 我附上 2 个样本:
右一个:
错误的:
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:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建两个相邻的不同标签。一份用于名称,一份用于其余部分。这样,名称标签的对齐方式就不会影响其他标签的对齐方式。
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.
尝试使用 组件.setComponentOrientation() 在标签上强制其按从左到右的顺序排列。
Try using Component.setComponentOrientation() on the label to force it to left-to-right order.