How can I restrict the size of a component in a BoxLayout?

Scott Stanchfield

BoxLayout respects the preferred, maximum and minimum sizes of its managed components.

You can manage the sizes in two ways:

  • Subclass your components and override their sizing methods:
    • getPreferredSize()
    • getMaximumSize()
    • getMinimumSize()
  • Drop the components inside a decorator that will manage the sizes.

I've created a set of beans that can help work with BoxLayout. See for "BoxBeans". In particular, the BoxAdapter bean decorates any component and provides four properties to control the maximum and minimum sizes of the contained components.

0 Comments  (click to add your comment)
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact