1
我使用Java中的BoxLayout佈局管理器,並對準一堆組件:對齊所有面板組件的java
myLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
myTextBox.setAlignmentX(Component.LEFT_ALIGNMENT);
myButton.setAlignmentX(Component.LEFT_ALIGNMENT);
...
我有很多組件,這似乎在上面。有速記方式嗎?
我試過以下,但setAlignmentX不是組件內的方法?
for (Component c : personPanel.getComponents()) {
c.setAlignmentX(Component.LEFT_ALIGNMENT);
}