javax.swing.plaf.basic

Class BasicBorders.MarginBorder

public static class BasicBorders.MarginBorder extends AbstractBorder implements Serializable, UIResource

An invisible, but spacing border whose margin is determined by calling the getMargin() method of the enclosed component. If the enclosed component has no such method, this border will not occupy any space.

[An illustration that shows how MarginBorder
 determines its borders]

Constructor Summary
MarginBorder()
Constructs a new MarginBorder.
Method Summary
InsetsgetBorderInsets(Component c)
Measures the width of this border.
InsetsgetBorderInsets(Component c, Insets insets)
Determines the insets of this border by calling the getMargin() method of the enclosed component.

Constructor Detail

MarginBorder

public MarginBorder()
Constructs a new MarginBorder.

Method Detail

getBorderInsets

public Insets getBorderInsets(Component c)
Measures the width of this border.

Parameters: c the component whose border is to be measured.

Returns: an Insets object whose left, right, top and bottom fields indicate the width of the border at the respective edge.

See Also: MarginBorder

getBorderInsets

public Insets getBorderInsets(Component c, Insets insets)
Determines the insets of this border by calling the getMargin() method of the enclosed component. The resulting margin will be stored into the the left, right, top and bottom fields of the passed insets parameter.

Unfortunately, getMargin() is not a method of {@link javax.swing.JComponent} or some other common superclass of things with margins. While reflection could be used to determine the existence of this method, this would be slow on many virtual machines. Therefore, the current implementation knows about {@link javax.swing.AbstractButton#getMargin()}, {@link javax.swing.JPopupMenu#getMargin()}, {@link javax.swing.JToolBar#getMargin()}, and {@link javax.swing.text.JTextComponent}. If c is an instance of a known class, the respective getMargin() method is called to determine the correct margin. Otherwise, a zero-width margin is returned.

Parameters: c the component whose border is to be measured.

Returns: the same object that was passed for insets, but with changed fields.