javax.swing.border

Class EtchedBorder

public class EtchedBorder extends AbstractBorder

A border that looks like an engraving etched into the background surface, or (in its raised variant) coming out of the surface plane. Using different constructors, it is possible to either explicitly specify the border colors, or to let the colors derive from the background color of the enclosed Component.

[An illustration of the two EtchedBorder variants]

Field Summary
protected intetchType
The type of this EtchedBorder, which is either {@link #RAISED} or {@link #LOWERED}.
protected Colorhighlight
The highlight color, or null to indicate that the color shall be derived from the background of the enclosed component.
static intLOWERED
Indicates that the border appears as engraved into the background.
static intRAISED
Indicates that the border appears as coming out of the background.
protected Colorshadow
The shadow color, or null to indicate that the color shall be derived from the background of the enclosed component.
Constructor Summary
EtchedBorder()
Constructs a lowered EtchedBorder.
EtchedBorder(int etchType)
Constructs an EtchedBorder with the specified appearance.
EtchedBorder(Color highlight, Color shadow)
Constructs a lowered EtchedBorder, explicitly selecting the colors that will be used for highlight and shadow.
EtchedBorder(int etchType, Color highlight, Color shadow)
Constructs an EtchedBorder with the specified appearance, explicitly selecting the colors that will be used for highlight and shadow.
Method Summary
InsetsgetBorderInsets(Component c)
Measures the width of this border.
InsetsgetBorderInsets(Component c, Insets insets)
Measures the width of this border, storing the results into a pre-existing Insets object.
intgetEtchType()
Returns the appearance of this EtchedBorder, which is either {@link #RAISED} or {@link #LOWERED}.
ColorgetHighlightColor(Component c)
Determines the color that will be used for highlighted parts when painting the border around a given component.
ColorgetHighlightColor()
Returns the color that will be used for highlighted parts when painting the border, or null if that color will be derived from the background of the enclosed Component.
ColorgetShadowColor(Component c)
Determines the color that will be used for shadowed parts when painting the border around a given component.
ColorgetShadowColor()
Returns the color that will be used for shadowed parts when painting the border, or null if that color will be derived from the background of the enclosed Component.
booleanisBorderOpaque()
Determines whether this border fills every pixel in its area when painting.
voidpaintBorder(Component c, Graphics g, int x, int y, int width, int height)
Paints the border for a given component.

Field Detail

etchType

protected int etchType
The type of this EtchedBorder, which is either {@link #RAISED} or {@link #LOWERED}.

highlight

protected Color highlight
The highlight color, or null to indicate that the color shall be derived from the background of the enclosed component.

LOWERED

public static final int LOWERED
Indicates that the border appears as engraved into the background.

RAISED

public static final int RAISED
Indicates that the border appears as coming out of the background.

shadow

protected Color shadow
The shadow color, or null to indicate that the color shall be derived from the background of the enclosed component.

Constructor Detail

EtchedBorder

public EtchedBorder()
Constructs a lowered EtchedBorder. The colors will be derived from the background color of the enclosed Component when the border gets painted.

EtchedBorder

public EtchedBorder(int etchType)
Constructs an EtchedBorder with the specified appearance. The colors will be derived from the background color of the enclosed Component when the border gets painted.

[An illustration of the two EtchedBorder variants]

Parameters: etchType the desired appearance of the border. The value must be either {@link #RAISED} or {@link #LOWERED}.

Throws: IllegalArgumentException if etchType has an unsupported value.

EtchedBorder

public EtchedBorder(Color highlight, Color shadow)
Constructs a lowered EtchedBorder, explicitly selecting the colors that will be used for highlight and shadow.

Parameters: highlight the color that will be used for painting the highlight part of the border. shadow the color that will be used for painting the shadow part of the border.

See Also: EtchedBorder

EtchedBorder

public EtchedBorder(int etchType, Color highlight, Color shadow)
Constructs an EtchedBorder with the specified appearance, explicitly selecting the colors that will be used for highlight and shadow.

[An illustration that shows which pixels get painted
 in what color]

Parameters: etchType the desired appearance of the border. The value must be either {@link #RAISED} or {@link #LOWERED}. highlight the color that will be used for painting the highlight part of the border. shadow the color that will be used for painting the shadow part of the border.

Throws: IllegalArgumentException if etchType has an unsupported value.

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: EtchedBorder

getBorderInsets

public Insets getBorderInsets(Component c, Insets insets)
Measures the width of this border, storing the results into a pre-existing Insets object.

Parameters: insets an Insets object for holding the result values. After invoking this method, the left, right, top and bottom fields indicate the width of the border at the respective edge.

Returns: the same object that was passed for insets.

See Also: getBorderInsets

getEtchType

public int getEtchType()
Returns the appearance of this EtchedBorder, which is either {@link #RAISED} or {@link #LOWERED}.

Returns: The type ({@link #RAISED} or {@link #LOWERED}).

getHighlightColor

public Color getHighlightColor(Component c)
Determines the color that will be used for highlighted parts when painting the border around a given component. If a highlight color has been specified upon constructing the border, that color is returned. Otherwise, the background color of the enclosed component is brightened.

Parameters: c the component enclosed by this border.

Returns: The color.

See Also: getBackground brighter

getHighlightColor

public Color getHighlightColor()
Returns the color that will be used for highlighted parts when painting the border, or null if that color will be derived from the background of the enclosed Component.

Returns: The highlight color (possibly null).

getShadowColor

public Color getShadowColor(Component c)
Determines the color that will be used for shadowed parts when painting the border around a given component. If a shadow color has been specified upon constructing the border, that color is returned. Otherwise, the background color of the enclosed component is darkened.

Parameters: c the component enclosed by this border.

Returns: The shadow color.

See Also: getBackground darker

getShadowColor

public Color getShadowColor()
Returns the color that will be used for shadowed parts when painting the border, or null if that color will be derived from the background of the enclosed Component.

Returns: The shadow color (possibly null).

isBorderOpaque

public boolean isBorderOpaque()
Determines whether this border fills every pixel in its area when painting.

If the border colors are derived from the background color of the enclosed component, the result is true because the derivation method always returns opaque colors. Otherwise, the result depends on the opacity of the individual colors.

Returns: true if the border is fully opaque, or false if some pixels of the background can shine through the border.

paintBorder

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
Paints the border for a given component.

Parameters: c the component whose border is to be painted. g the graphics for painting. x the horizontal position for painting the border. y the vertical position for painting the border. width the width of the available area for painting the border. height the height of the available area for painting the border.