* If you put glue before the first fixed-size component
* and after the second fixed-size component,
* the fixed-size components are centered in the box.
*
* <p>
*
* To use glue,
* call <code>Box.createGlue</code>
* and add the returned component to a container.
* The glue component has no minimum or preferred size,
* so it takes no space unless excess space is available.
* If excess space is available,
* then the glue component takes its share of available
* horizontal or vertical space,
* just like any other component that has no maximum width or height.
*
* @return the component
*/
public static Component createGlue() {
return new Filler(new Dimension(0,0), new Dimension(0,0),
new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
}
/**
* Creates a horizontal glue component.
*
* @return the component
*/
public static Component createHorizontalGlue() {
return new Filler(new Dimension(0,0), new Dimension(0,0),
new Dimension(Short.MAX_VALUE, 0));
}
/**
* Creates a vertical glue component.
*
* @return the component
*/
public static Component createVerticalGlue() {
return new Filler(new Dimension(0,0), new Dimension(0,0),
new Dimension(0, Short.MAX_VALUE));
}
/**
* Throws an AWTError, since a Box can use only a BoxLayout.
*
* @param l the layout manager to use
*/
public void setLayout(LayoutManager l) {
throw new AWTError("Illegal request");
}
/**
* Paints this <code>Box</code>. If this <code>Box</code> has a UI this
* method invokes super's implementation, otherwise if this
* <code>Box</code> is opaque the <code>Graphics</code> is filled
* using the background.
*
* @param g the <code>Graphics</code> to paint to
* @throws NullPointerException if <code>g</code> is null
* @since 1.6
*/
protected void paintComponent(Graphics g) {
if (ui != null) {
// On the off chance some one created a UI, honor it
super.paintComponent(g);
} else if (isOpaque()) {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
}
}
/**
* An implementation of a lightweight component that participates in
* layout but has no view.
* <p>
* <strong>Warning:</strong>
* Serialized objects of this class will not be compatible with
* future Swing releases. The current serialization support is
* appropriate for short term storage or RMI between applications running
* the same version of Swing. As of 1.4, support for long term storage
* of all JavaBeans<sup><font size="-2">TM</font></sup>
* has been added to the <code>java.beans</code> package.
* Please see {@link java.beans.XMLEncoder}.
*/
public static class Filler extends JComponent implements Accessible {
/**
* Constructor to create shape with the given size ranges.
*
* @param min Minimum size
* @param pref Preferred size
* @param max Maximum size
*/
public Filler(Dimension min, Dimension pref, Dimension max) {
setMinimumSize(min);
setPreferredSize(pref);
setMaximumSize(max);
}
=3= |