Java Reference
In-Depth Information
Figure 14-18. EntryLayout in action
The methods for the LayoutManager interface are shown in Table 14-2 .
Table 14-2. LayoutManager methods
Method name
Description
Like getPreferredSize() for a component: the “best” size for the container
preferredLayoutSize(Container )
Same, but for the minimum workable size
minimumLayoutSize( Container )
Perform the layout calculations, and resize and reposition all the compon-
ents at the current size of the container
layoutContainer(Container)
Associate a constraint with a given component (you normally store these
mappings in a java.util.Map )
addLayoutComponent(String, Com-
ponent)
removeLayoutComponent(Component) Remove a component from the HashMap
If you don't need Constraint objects (such as BorderLayout.NORTH or a GridBagCon-
straint object), you can ignore the last two methods. Well, you can't ignore them com-
pletely. Because this is an interface, you must implement them. But they can be as simple as
{} (i.e., a null-bodied method).
That leaves only three serious methods. The first, preferredLayoutSize() , normally loops
through all the components—either in the HashMap if using constraints, or in an array re-
turned by the container's getComponents() method—asking each for its preferred size and
adding them up, while partly doing the layout calculations. And minimumLayoutSize() is
the same for the smallest possible layout that will work. It may be possible for these methods
to delegate either to a common submethod or to invoke layoutContainer() , depending on
how the given layout policy works.
Search WWH ::




Custom Search