Java中BoxLayout的JLabel问题
我有一个带有 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所有组件都需要将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.