javax.swing.border

Class LineBorder

public class LineBorder extends AbstractBorder

A border that consists of a line whose thickness and color can be specified. There also is a variant with rounded corners.
Field Summary
protected ColorlineColor
The color of the line.
protected booleanroundedCorners
Indicates whether the line is drawn with rounded corners (true) or not ((false).
protected intthickness
The width of the line in pixels.
Constructor Summary
LineBorder(Color color)
Constructs a LineBorder given its color.
LineBorder(Color color, int thickness)
Constructs a LineBorder given its color and thickness.
LineBorder(Color color, int thickness, boolean roundedCorners)
Constructs a LineBorder given its color, thickness, and whether it has rounded corners.
Method Summary
static BordercreateBlackLineBorder()
Returns a black, one pixel thick, plain {@link LineBorder}.
static BordercreateGrayLineBorder()
Returns a gray, one pixel thick, plain {@link LineBorder}.
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.
ColorgetLineColor()
Returns the color of the line.
booleangetRoundedCorners()
Returns whether this LineBorder os drawm with rounded or with plain corners.
intgetThickness()
Returns the thickness of the line in pixels.
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 line border around a given Component.

Field Detail

lineColor

protected Color lineColor
The color of the line.

roundedCorners

protected boolean roundedCorners
Indicates whether the line is drawn with rounded corners (true) or not ((false).

thickness

protected int thickness
The width of the line in pixels.

Constructor Detail

LineBorder

public LineBorder(Color color)
Constructs a LineBorder given its color. The border will be one pixel thick and have plain corners.

Parameters: color the color for drawing the border.

See Also: LineBorder

LineBorder

public LineBorder(Color color, int thickness)
Constructs a LineBorder given its color and thickness. The border will have plain corners.

Parameters: color the color for drawing the border. thickness the width of the line in pixels.

See Also: LineBorder

LineBorder

public LineBorder(Color color, int thickness, boolean roundedCorners)
Constructs a LineBorder given its color, thickness, and whether it has rounded corners.

[An illustration of two LineBorders]

Note that the enlarged view in the right-hand picture shows that the implementation draws one more pixel than specified, provided that roundedCorders is true and anti-aliasing is turned on while painting. While this might be considered a bug, the Sun reference implementation (at least JDK 1.3.1 on Apple MacOS X 10.1.5) can be observed to fill exactly the same pixels as shown above. The GNU Classpath LineBorder replicates the observed behavior of the Sun implementation.

Parameters: color the color for drawing the border. thickness the width of the line in pixels. roundedCorners true for rounded corners, false for plain corners.

Since: 1.3

Method Detail

createBlackLineBorder

public static Border createBlackLineBorder()
Returns a black, one pixel thick, plain {@link LineBorder}. The method may always return the same (singleton) {@link LineBorder} instance.

Returns: The border.

createGrayLineBorder

public static Border createGrayLineBorder()
Returns a gray, one pixel thick, plain {@link LineBorder}. The method may always return the same (singleton) {@link LineBorder} instance.

Returns: The border.

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, which is the thickness of the line.

See Also: LineBorder

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, which is the thickness of the line.

Returns: the same object that was passed for insets.

See Also: getBorderInsets

getLineColor

public Color getLineColor()
Returns the color of the line.

Returns: The line color (never null).

getRoundedCorners

public boolean getRoundedCorners()
Returns whether this LineBorder os drawm with rounded or with plain corners.

Returns: true if the corners are rounded, false if the corners are plain.

getThickness

public int getThickness()
Returns the thickness of the line in pixels.

Returns: The line thickness (in pixels).

isBorderOpaque

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

Returns: true if the corners are plain and the line color is fully opaque; false if the corners are rounded or the line color is partially transparent.

paintBorder

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
Paints the line border around 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.