I would like to have all elements in my JPanel to be aligned to the left. I try to do it in the following way:
JPanel panel = new JPanel();
panel.setLayout(n
You should use setAlignmentX(..) on components you want to align, not on the container that has them..
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(c1);
panel.add(c2);
c1.setAlignmentX(Component.LEFT_ALIGNMENT);
c2.setAlignmentX(Component.LEFT_ALIGNMENT);