Java Reference
In-Depth Information
setupButtons(SET_CENTRAL);
JPanel actionPanel = new JPanel();
actionPanel.setBorder(BorderFactory.createTitledBorder("Change Alignment"));
String actionSettings[] = {SET_MINIMUM, SET_MAXIMUM, SET_CENTRAL,
SET_MIXED};
for (int i=0, n=actionSettings.length; i<n; i++) {
JButton button = new JButton(actionSettings[i]);
button.addActionListener(sizingActionListener);
actionPanel.add(button);
}
frame.add(panel, BorderLayout.CENTER);
frame.add(actionPanel, BorderLayout.SOUTH);
frame.setSize(400, 300);
frame.setVisible(true);
}
};
EventQueue.invokeLater(runner);
}
}
SizeRequirements Class
The BoxLayout and OverlayLayout managers rely on the SizeRequirements class to determine
the exact positions of the contained components. The SizeRequirements class contains various
static methods to assist in the calculations necessary to position components in either an
aligned or a tiled manner. The layout managers use this class to calculate their components' x
coordinates and width and y coordinates and height. Each pair is calculated separately. If the
associated layout manager needs both sets of attributes for positioning, the layout manager
asks the SizeRequirements class separately for each.
ScrollPaneLayout Class
The JScrollPane class, a container class that will be described in Chapter 11, uses the
ScrollPaneLayout manager. Trying to use the layout manager outside a JScrollPane isn't
possible because the layout manager checks to see if the container object associated with
the layout manager is an instance of JScrollPane . See Chapter 11 for a complete description
of this layout manager (and its associated ScrollPaneConstants interface) in the context of
the JScrollPane .
Search WWH ::




Custom Search