Java中BoxLayout的JLabel问题

发布于 2024-10-04 22:48:43 字数 509 浏览 1 评论 0原文

我有一个带有 BoxLayout 声明如下的面板:

  venueInfoPanel.setLayout(new BoxLayout(venueInfoPanel, BoxLayout.Y_AXIS));

当我向此面板添加两个 JTextArea 时,它们都向左对齐,这就是我想要的。但是,当我添加 JLabel 时,它会将自身对齐到中心,而不是左侧。这是为什么呢?我怎样才能使它与所有其他 JTextArea 对齐?我在此处阅读了文档,发现我使用了Component。 LEFT_ALIGNMENT 我通过执行

label.setAlignmentX(label.LEFT_ALIGNMENT);

其中 label 是我想要添加到 JPanel 的 JLabel来做到这一点

I have a panel with a BoxLayout declared as follows:

  venueInfoPanel.setLayout(new BoxLayout(venueInfoPanel, BoxLayout.Y_AXIS));

When I add two JTextArea to this panel, they all align to the left, which is what I want. However, when I add a JLabel, it aligns itself to the center, instead of to the left. Why is this? How can I make it so it aligns with all the other JTextArea? I read the document here and found out that I use Component.LEFT_ALIGNMENT and I did that by doing

label.setAlignmentX(label.LEFT_ALIGNMENT);

where label is the JLabel I wanted to add to the JPanel

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苍景流年 2024-10-11 22:48:43

所有组件都需要将alignmentX设置为左侧。您引用的教程有很多工作示例。你应该能够自己弄清楚。如果您仍然遇到问题,请发布您的 SSCCE 来演示问题。

All components need the alignmentX set to left. The tutorial you referenced has plenty of working examples. You should be able to figure it out on your own. If you still have a problem post your SSCCE demonstrating the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文