Java Notes
BoxLayout alignment
Component alignment
Alignment is a property of the component, not the layout. but box layout will respect the . Generally you want all components in a box to have the same alignment (eg, left/top, center, or right/bottom). Set the X alignment for components in a vertical box and the Y alignment for components in a horizontal box.myComponent.setAlignmentX(align); // For vertical layouts myComponent.setAlignmentY(align); // For horizontal layoutsWhere
align
is one of the following constants from the
java.awt.Component
class.
Component.LEFT_ALIGNMENT
Component.CENTER_ALIGNMENT
- for both horizontal or vertical layouts.Component.RIGHT_ALIGNMENT
Component.TOP_ALIGNMENT
Component.BOTTOM_ALIGNMENT
Doesn't align subpanels?
I didn't have any luck setting the alignment of a subpanel I added to a BoxLayout, altho it worked for normal "components".