Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top