javax.swing.border

Class TitledBorder

public class TitledBorder extends AbstractBorder

A border that paints a title on top of another border.
Field Summary
static intABOVE_BOTTOM
A value for the titlePosition property that vertically positions the title text above the bottom line of the border.
static intABOVE_TOP
A value for the titlePosition property that vertically positions the title text above the top line of the border.
protected Borderborder
The border underneath the title.
static intBELOW_BOTTOM
A value for the titlePosition property that vertically positions the title text below the bottom line of the border.
static intBELOW_TOP
A value for the titlePosition property that vertically positions the title text below the top line of the border.
static intBOTTOM
A value for the titlePosition property that vertically positions the title text at the center of the bottom line of the border.
static intCENTER
A value for the titleJustification property that horizontally aligns the title text with the center of the border.
static intDEFAULT_JUSTIFICATION
A value for the titleJustification property that horizontally aligns the title text with either the left or the right edge of the border, depending on the orientation of the component nested into the border.
static intDEFAULT_POSITION
A value for the titlePosition property that vertically positions the title text at the default vertical position, which is in the middle of the top line of the border.
protected static intEDGE_SPACING
The number of pixels between the inside of {@link #border} and the bordered component.
static intLEADING
A value for the titleJustification property that horizontally aligns the title text with either the left or the right edge of the border, depending on the orientation of the component nested into the border.
static intLEFT
A value for the titleJustification property that horizontally aligns the title text with the left-hand edge of the border.
static intRIGHT
A value for the titleJustification property that horizontally aligns the title text with the right-hand edge of the border.
protected Stringtitle
The title, or null to display no title.
protected ColortitleColor
The color for displaying the title text.
protected FonttitleFont
The font for displaying the title text.
protected inttitleJustification
The horizontal alignment of the title text in relation to the border, which is one of {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}.
protected inttitlePosition
The vertical position of the title text relative to the border, which is one of {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}.
protected static intTEXT_INSET_H
The number of pixels between the outside of this TitledBorder and the beginning (if left-aligned) or end (if right-aligned) of the title text.
protected static intTEXT_SPACING
The number of pixels between the title text and {@link #border}.
static intTOP
A value for the titlePosition property that vertically positions the title text at the middle of the top line of the border.
static intTRAILING
A value for the titleJustification property that horizontally aligns the title text with either the right or the left edge of the border, depending on the orientation of the component nested into the border.
Constructor Summary
TitledBorder(String title)
Constructs a TitledBorder given the text of its title.
TitledBorder(Border border)
Constructs an initially untitled TitledBorder given another border.
TitledBorder(Border border, String title)
Constructs a TitledBorder given its border and title text.
TitledBorder(Border border, String title, int titleJustification, int titlePosition)
Constructs a TitledBorder given its border, title text, horizontal alignment, and vertical position.
TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont)
Constructs a TitledBorder given its border, title text, horizontal alignment, vertical position, and font.
TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)
Constructs a TitledBorder given its border, title text, horizontal alignment, vertical position, font, and color.
Method Summary
BordergetBorder()
Retrieves the border underneath the title.
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.
protected FontgetFont(Component c)
Returns the font that is used for displaying the title text for a given Component.
DimensiongetMinimumSize(Component c)
Calculates the minimum size needed for displaying the border and its title.
StringgetTitle()
Returns the text of the title.
ColorgetTitleColor()
Retrieves the color for displaying the title text.
FontgetTitleFont()
Retrieves the font for displaying the title text.
intgetTitleJustification()
Returns the horizontal alignment of the title text in relation to the border.
intgetTitlePosition()
Returns the vertical position of the title text in relation to the border.
booleanisBorderOpaque()
Returns false, indicating that there are pixels inside the area of this border where the background shines through.
voidpaintBorder(Component c, Graphics g, int x, int y, int width, int height)
Paints the border and the title text.
voidsetBorder(Border border)
Sets the border underneath the title.
voidsetTitle(String title)
Sets the text of the title.
voidsetTitleColor(Color titleColor)
Sets the color for displaying the title text.
voidsetTitleFont(Font titleFont)
Sets the font for displaying the title text.
voidsetTitleJustification(int titleJustification)
Sets the horizontal alignment of the title text in relation to the border.
voidsetTitlePosition(int titlePosition)
Sets the vertical position of the title text in relation to the border.

Field Detail

ABOVE_BOTTOM

public static final int ABOVE_BOTTOM
A value for the titlePosition property that vertically positions the title text above the bottom line of the border.

See Also: getTitlePosition TitledBorder

ABOVE_TOP

public static final int ABOVE_TOP
A value for the titlePosition property that vertically positions the title text above the top line of the border.

See Also: getTitlePosition TitledBorder

border

protected Border border
The border underneath the title. If this value is null, the border will be retrieved from the {@link javax.swing.UIManager}’s defaults table using the key TitledBorder.border.

BELOW_BOTTOM

public static final int BELOW_BOTTOM
A value for the titlePosition property that vertically positions the title text below the bottom line of the border.

See Also: getTitlePosition TitledBorder

BELOW_TOP

public static final int BELOW_TOP
A value for the titlePosition property that vertically positions the title text below the top line of the border.

See Also: getTitlePosition TitledBorder

BOTTOM

public static final int BOTTOM
A value for the titlePosition property that vertically positions the title text at the center of the bottom line of the border.

See Also: getTitlePosition TitledBorder

CENTER

public static final int CENTER
A value for the titleJustification property that horizontally aligns the title text with the center of the border.

See Also: getTitleJustification TitledBorder

DEFAULT_JUSTIFICATION

public static final int DEFAULT_JUSTIFICATION
A value for the titleJustification property that horizontally aligns the title text with either the left or the right edge of the border, depending on the orientation of the component nested into the border. If the component orientation is left-to-right, the title text is aligned with the left edge; otherwise, it is aligned with the right edge. This is the same behavior as with {@link #LEADING}.

See Also: getTitleJustification TitledBorder isLeftToRight

DEFAULT_POSITION

public static final int DEFAULT_POSITION
A value for the titlePosition property that vertically positions the title text at the default vertical position, which is in the middle of the top line of the border.

See Also: getTitlePosition TitledBorder

EDGE_SPACING

protected static final int EDGE_SPACING
The number of pixels between the inside of {@link #border} and the bordered component.

LEADING

public static final int LEADING
A value for the titleJustification property that horizontally aligns the title text with either the left or the right edge of the border, depending on the orientation of the component nested into the border. If the component orientation is left-to-right, the title text is aligned with the left edge; otherwise, it is aligned with the right edge. This is the same behavior as with {@link #DEFAULT_JUSTIFICATION}.

See Also: getTitleJustification TitledBorder isLeftToRight

LEFT

public static final int LEFT
A value for the titleJustification property that horizontally aligns the title text with the left-hand edge of the border.

See Also: getTitleJustification TitledBorder

RIGHT

public static final int RIGHT
A value for the titleJustification property that horizontally aligns the title text with the right-hand edge of the border.

See Also: getTitleJustification TitledBorder

title

protected String title
The title, or null to display no title.

titleColor

protected Color titleColor
The color for displaying the title text. If this value is null, the color will be retrieved from the {@link javax.swing.UIManager}’s defaults table using the key TitledBorder.titleColor.

titleFont

protected Font titleFont
The font for displaying the title text. If this value is null, the font will be retrieved from the {@link javax.swing.UIManager}’s defaults table using the key TitledBorder.font.

titleJustification

protected int titleJustification
The horizontal alignment of the title text in relation to the border, which is one of {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}.

titlePosition

protected int titlePosition
The vertical position of the title text relative to the border, which is one of {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}.

TEXT_INSET_H

protected static final int TEXT_INSET_H
The number of pixels between the outside of this TitledBorder and the beginning (if left-aligned) or end (if right-aligned) of the title text.

TEXT_SPACING

protected static final int TEXT_SPACING
The number of pixels between the title text and {@link #border}. This value is only relevant if the title text does not intersect {@link #border}. No intersection occurs if {@link #titlePosition} is one of {@link #ABOVE_TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, or {@link #BELOW_BOTTOM}.

TOP

public static final int TOP
A value for the titlePosition property that vertically positions the title text at the middle of the top line of the border.

See Also: getTitlePosition TitledBorder

TRAILING

public static final int TRAILING
A value for the titleJustification property that horizontally aligns the title text with either the right or the left edge of the border, depending on the orientation of the component nested into the border. If the component orientation is left-to-right, the title text is aligned with the right edge; otherwise, it is aligned with the left edge.

See Also: getTitleJustification TitledBorder isLeftToRight

Constructor Detail

TitledBorder

public TitledBorder(String title)
Constructs a TitledBorder given the text of its title.

Parameters: title the title text, or null to use no title text.

TitledBorder

public TitledBorder(Border border)
Constructs an initially untitled TitledBorder given another border.

Parameters: border the border underneath the title, or null to use a default from the current look and feel.

TitledBorder

public TitledBorder(Border border, String title)
Constructs a TitledBorder given its border and title text.

Parameters: border the border underneath the title, or null to use a default from the current look and feel. title the title text, or null to use no title text.

TitledBorder

public TitledBorder(Border border, String title, int titleJustification, int titlePosition)
Constructs a TitledBorder given its border, title text, horizontal alignment, and vertical position.

Parameters: border the border underneath the title, or null to use a default from the current look and feel. title the title text, or null to use no title text. titleJustification the horizontal alignment of the title text in relation to the border. The value must be one of {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}. titlePosition the vertical position of the title text in relation to the border. The value must be one of {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}.

Throws: IllegalArgumentException if titleJustification or titlePosition have an unsupported value.

TitledBorder

public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont)
Constructs a TitledBorder given its border, title text, horizontal alignment, vertical position, and font.

Parameters: border the border underneath the title, or null to use a default from the current look and feel. title the title text, or null to use no title text. titleJustification the horizontal alignment of the title text in relation to the border. The value must be one of {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}. titlePosition the vertical position of the title text in relation to the border. The value must be one of {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}. titleFont the font for the title text, or null to use a default from the current look and feel.

Throws: IllegalArgumentException if titleJustification or titlePosition have an unsupported value.

TitledBorder

public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)
Constructs a TitledBorder given its border, title text, horizontal alignment, vertical position, font, and color.

Parameters: border the border underneath the title, or null to use a default from the current look and feel. title the title text, or null to use no title text. titleJustification the horizontal alignment of the title text in relation to the border. The value must be one of {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}. titlePosition the vertical position of the title text in relation to the border. The value must be one of {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}. titleFont the font for the title text, or null to use a default from the current look and feel. titleColor the color for the title text, or null to use a default from the current look and feel.

Throws: IllegalArgumentException if titleJustification or titlePosition have an unsupported value.

Method Detail

getBorder

public Border getBorder()
Retrieves the border underneath the title. If no border has been set, or if it has been set tonull, the current {@link javax.swing.LookAndFeel} will be asked for a border using the key TitledBorder.border.

Returns: a border, or null if the current LookAndFeel does not provide a border for the key TitledBorder.border.

See Also: getBorder

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

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

getFont

protected Font getFont(Component c)
Returns the font that is used for displaying the title text for a given Component.

Parameters: c the Component for which this TitledBorder is the border.

Returns: The font returned by {@link #getTitleFont()}, or a fallback if {@link #getTitleFont()} returned null.

getMinimumSize

public Dimension getMinimumSize(Component c)
Calculates the minimum size needed for displaying the border and its title.

Parameters: c the Component for which this TitledBorder constitutes a border.

Returns: The minimum size.

getTitle

public String getTitle()
Returns the text of the title.

Returns: the title text, or null if no title is displayed.

getTitleColor

public Color getTitleColor()
Retrieves the color for displaying the title text. If no color has been set, or if it has been set tonull, the current {@link javax.swing.LookAndFeel} will be asked for a color using the key TitledBorder.titleColor.

Returns: a color, or null if the current LookAndFeel does not provide a color for the key TitledBorder.titleColor.

See Also: getColor

getTitleFont

public Font getTitleFont()
Retrieves the font for displaying the title text. If no font has been set, or if it has been set tonull, the current {@link javax.swing.LookAndFeel} will be asked for a font using the key TitledBorder.font.

Returns: a font, or null if the current LookAndFeel does not provide a font for the key TitledBorder.font.

See Also: getFont

getTitleJustification

public int getTitleJustification()
Returns the horizontal alignment of the title text in relation to the border.

Returns: one of the values {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}.

getTitlePosition

public int getTitlePosition()
Returns the vertical position of the title text in relation to the border.

Returns: one of the values {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}.

isBorderOpaque

public boolean isBorderOpaque()
Returns false, indicating that there are pixels inside the area of this border where the background shines through.

Returns: false.

paintBorder

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
Paints the border and the title text.

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.

setBorder

public void setBorder(Border border)
Sets the border underneath the title.

Parameters: border a border, or null to use the border that is supplied by the current LookAndFeel.

See Also: getBorder

setTitle

public void setTitle(String title)
Sets the text of the title.

Parameters: title the new title text, or null for displaying no text at all.

setTitleColor

public void setTitleColor(Color titleColor)
Sets the color for displaying the title text.

Parameters: titleColor the color, or null to use the color provided by the current {@link javax.swing.LookAndFeel}.

See Also: getTitleColor

setTitleFont

public void setTitleFont(Font titleFont)
Sets the font for displaying the title text.

Parameters: titleFont the font, or null to use the font provided by the current {@link javax.swing.LookAndFeel}.

See Also: getTitleFont

setTitleJustification

public void setTitleJustification(int titleJustification)
Sets the horizontal alignment of the title text in relation to the border.

Parameters: titleJustification the new alignment, which must be one of {@link #LEFT}, {@link #CENTER}, {@link #RIGHT}, {@link #LEADING}, {@link #TRAILING}, or {@link #DEFAULT_JUSTIFICATION}.

Throws: IllegalArgumentException if an unsupported value is passed for titleJustification.

setTitlePosition

public void setTitlePosition(int titlePosition)
Sets the vertical position of the title text in relation to the border.

Parameters: titlePosition one of the values {@link #ABOVE_TOP}, {@link #TOP}, {@link #BELOW_TOP}, {@link #ABOVE_BOTTOM}, {@link #BOTTOM}, {@link #BELOW_BOTTOM}, or {@link #DEFAULT_POSITION}.

Throws: IllegalArgumentException if an unsupported value is passed for titlePosition.