Home Java Java-tips GUI Layouts BoxLayout alignment

Ask Questions?

View Latest Questions



BoxLayout alignment
Posted on: July 26, 2006 at 12:00 AM
About BoxLayout alignment

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 layouts
Where 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.TOP_ALIGNMENT
Copyleft 2003 Fred Swartz MIT License, Last update: 2003-04-30