Which layouts respect which sizing methods?

Scott Stanchfield

The Component class defines several size accessor methods to assist the layout process. Each of these methods returns a Dimension object describing the requested size. These methods are as follows:

  • public Dimension getPreferredSize()
    This returns the desired size for a component.
  • public Dimension getMinimumSize()
    This returns the smallest desired size for a component.
  • public Dimension getMaximumSize()
    This returns the largest desired size for a component.

Layout managers will use these sizing methods when they are figuring out where to place components and what size they should be. Layout managers can respect or ignore as much or as little of this information as they see fit. Each layout manager has its own algorithm and may or may not use this information when deciding component placement. Which of these methods is respected or ignored is very important information and should be documented carefully when creating your own layout manager.

For the six standard layout managers:
Layout Manager Respects...
BorderLayout preferred height (NORTH, SOUTH)
preferred width (EAST, WEST)
FlowLayout preferred size
CardLayout none
GridLayout none
BoxLayout preferred size
maximum size
minimum size
GridBagLayout preferred size (for initial component sizes)
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


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

 

 

About | Sitemap | Contact