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(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.setAlignmentX(Component.LEFT_ALIGNMENT);
As a result Java use left side of all elements as a position of the element and then put all elements in the center (not left part) of the JPanel.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…