Top Description Fields Constructors Methods
javax.swing.border

public Class TitledBorder

extends AbstractBorder
Class Inheritance
Known Direct Subclasses
javax.swing.plaf.BorderUIResource.TitledBorderUIResource
Annotations
@SuppressWarnings:serial
Imports
java.awt.Color, .Component, .Dimension, .Font, .Graphics, .Graphics2D, .Insets, .Rectangle, java.awt.geom.Path2D, java.beans.ConstructorProperties, .PropertyChangeEvent, .PropertyChangeListener, java.lang.ref.WeakReference, javax.swing.JComponent, .JLabel, .UIManager, javax.swing.plaf.basic.BasicHTML, jdk.internal.ref.CleanerFactory

A class which implements an arbitrary border with the addition of a String title in a specified position and justification.

If the border, font, or color property values are not specified in the constructor or by invoking the appropriate set methods, the property values will be defined by the current look and feel, using the following property names in the Defaults Table:

Warning

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 has been added to the java.beans package. Please see java.beans.XMLEncoder.

Authors
David Kloba, Amy Fowler

Field Summary

Modifier and TypeField and Description
public static final int
ABOVE_BOTTOM

Position the title above the border's bottom line.

public static final int
ABOVE_TOP

Position the title above the border's top line.

public static final int
BELOW_BOTTOM

Position the title below the border's bottom line.

public static final int
BELOW_TOP

Position the title below the border's top line.

protected Border
border

The border.

public static final int
BOTTOM

Position the title in the middle of the border's bottom line.

public static final int
CENTER

Position title text in the center of the border line.

public static final int
DEFAULT_JUSTIFICATION

Use the default justification for the title text.

public static final int
DEFAULT_POSITION

Use the default vertical orientation for the title text.

protected static final int
EDGE_SPACING

Space between the border and the component's edge

private final JLabel
public static final int
LEADING

Position title text at the left side of the border line for left to right orientation, at the right side of the border line for right to left orientation.

public static final int
LEFT

Position title text at the left side of the border line.

public static final int
RIGHT

Position title text at the right side of the border line.

protected static final int
TEXT_INSET_H

Horizontal inset of text that is left or right justified

protected static final int
TEXT_SPACING

Space between the border and text

protected String
title

The title the border should display.

protected Color
titleColor

The color of the title.

protected Font
titleFont

The font for rendering the title.

protected int
titleJustification

The justification for the title.

protected int
titlePosition

The position for the title.

public static final int
TOP

Position the title in the middle of the border's top line.

public static final int
TRAILING

Position title text at the right side of the border line for left to right orientation, at the left side of the border line for right to left orientation.

Constructor Summary

AccessConstructor and Description
public
TitledBorder(String
the title the border should display
title
)

Creates a TitledBorder instance.

public
TitledBorder(Border
the border
border
)

Creates a TitledBorder instance with the specified border and an empty title.

public
TitledBorder(Border
the border
border
,
String
the title the border should display
title
)

Creates a TitledBorder instance with the specified border and title.

public
TitledBorder(Border
the border
border
,
String
the title the border should display
title
,
int
the justification for the title
titleJustification
,
int
the position for the title
titlePosition
)

Creates a TitledBorder instance with the specified border, title, title-justification, and title-position.

public
TitledBorder(Border
the border
border
,
String
the title the border should display
title
,
int
the justification for the title
titleJustification
,
int
the position for the title
titlePosition
,
Font
the font for rendering the title
titleFont
)

Creates a TitledBorder instance with the specified border, title, title-justification, title-position, and title-font.

public
TitledBorder(Border
the border
border
,
String
the title the border should display
title
,
int
the justification for the title
titleJustification
,
int
the position for the title
titlePosition
,
Font
the font of the title
titleFont
,
Color
the color of the title
titleColor
)

Creates a TitledBorder instance with the specified border, title, title-justification, title-position, title-font, and title-color.

Method Summary

Modifier and TypeMethod and Description
public int
getBaseline(Component
Component baseline is being requested for
c
,
int
the width to get the baseline for
width
,
int
the height to get the baseline for
height
)

Overrides javax.swing.border.AbstractBorder.getBaseline.

Returns the baseline.

public Component.BaselineResizeBehavior
getBaselineResizeBehavior(Component
Component to return baseline resize behavior for
c
)

Overrides javax.swing.border.AbstractBorder.getBaselineResizeBehavior.

Returns an enum indicating how the baseline of the border changes as the size changes.

public Border

Returns:

the border of the titled border
getBorder
()

Returns the border of the titled border.

public Insets
getBorderInsets(Component
the component for which this border insets value applies
c
,
Insets
the object to be reinitialized
insets
)

Overrides javax.swing.border.AbstractBorder.getBorderInsets.

Reinitialize the insets parameter with this Border's current Insets.

private static Insets
private Color
protected Font

Returns:

default font of the titled border
getFont
(Component
the component
c
)

Returns default font of the titled border.

private int
private JLabel
public Dimension

Returns:

the Dimension object
getMinimumSize
(Component
the component where this border will be drawn
c
)

Returns the minimum dimensions this border requires in order to fully display the border and title.

private int
public String

Returns:

the title of the titled border
getTitle
()

Returns the title of the titled border.

public Color

Returns:

the title-color of the titled border
getTitleColor
()

Returns the title-color of the titled border.

public Font

Returns:

the title-font of the titled border
getTitleFont
()

Returns the title-font of the titled border.

public int

Returns:

the title-justification of the titled border
getTitleJustification
()

Returns the title-justification of the titled border.

public int

Returns:

the title-position of the titled border
getTitlePosition
()

Returns the title-position of the titled border.

private void
public boolean
isBorderOpaque()

Overrides javax.swing.border.AbstractBorder.isBorderOpaque.

Implements javax.swing.border.Border.isBorderOpaque.

Returns whether or not the border is opaque.

public void
paintBorder(Component
the component for which this border is being painted
c
,
Graphics
the paint graphics
g
,
int
the x position of the painted border
x
,
int
the y position of the painted border
y
,
int
the width of the painted border
width
,
int
the height of the painted border
height
)

Overrides javax.swing.border.AbstractBorder.paintBorder.

Implements javax.swing.border.Border.paintBorder.

Paints the border for the specified component with the specified position and size.

public void
setBorder(Border
the border
border
)

Sets the border of the titled border.

public void
setTitle(String
the title for the border
title
)

Sets the title of the titled border.

public void
setTitleColor(Color
the color for the border title
titleColor
)

Sets the title-color of the titled border.

public void
setTitleFont(Font
the font for the border title
titleFont
)

Sets the title-font of the titled border.

public void
setTitleJustification(int
the justification for the border
titleJustification
)

Sets the title-justification of the titled border.

public void
setTitlePosition(int
the position for the border
titlePosition
)

Sets the title-position of the titled border.

Inherited from javax.swing.border.AbstractBorder:
getBorderInsetsgetInteriorRectanglegetInteriorRectangleisLeftToRight

Field Detail

ABOVE_BOTTOMback to summary
public static final int ABOVE_BOTTOM

Position the title above the border's bottom line.

ABOVE_TOPback to summary
public static final int ABOVE_TOP

Position the title above the border's top line.

BELOW_BOTTOMback to summary
public static final int BELOW_BOTTOM

Position the title below the border's bottom line.

BELOW_TOPback to summary
public static final int BELOW_TOP

Position the title below the border's top line.

borderback to summary
protected Border border

The border.

BOTTOMback to summary
public static final int BOTTOM

Position the title in the middle of the border's bottom line.

CENTERback to summary
public static final int CENTER

Position title text in the center of the border line.

DEFAULT_JUSTIFICATIONback to summary
public static final int DEFAULT_JUSTIFICATION

Use the default justification for the title text.

DEFAULT_POSITIONback to summary
public static final int DEFAULT_POSITION

Use the default vertical orientation for the title text.

EDGE_SPACINGback to summary
protected static final int EDGE_SPACING

Space between the border and the component's edge

labelback to summary
private final JLabel label
LEADINGback to summary
public static final int LEADING

Position title text at the left side of the border line for left to right orientation, at the right side of the border line for right to left orientation.

LEFTback to summary
public static final int LEFT

Position title text at the left side of the border line.

TEXT_INSET_Hback to summary
protected static final int TEXT_INSET_H

Horizontal inset of text that is left or right justified

TEXT_SPACINGback to summary
protected static final int TEXT_SPACING

Space between the border and text

titleback to summary
protected String title

The title the border should display.

titleColorback to summary
protected Color titleColor

The color of the title.

titleFontback to summary
protected Font titleFont

The font for rendering the title.

titleJustificationback to summary
protected int titleJustification

The justification for the title.

titlePositionback to summary
protected int titlePosition

The position for the title.

TOPback to summary
public static final int TOP

Position the title in the middle of the border's top line.

TRAILINGback to summary
public static final int TRAILING

Position title text at the right side of the border line for left to right orientation, at the left side of the border line for right to left orientation.

Constructor Detail

TitledBorderback to summary
public TitledBorder(String title)

Creates a TitledBorder instance.

Parameters
title:String

the title the border should display

TitledBorderback to summary
public TitledBorder(Border border)

Creates a TitledBorder instance with the specified border and an empty title.

Parameters
border:Border

the border

TitledBorderback to summary
public TitledBorder(Border border, String title)

Creates a TitledBorder instance with the specified border and title.

Parameters
border:Border

the border

title:String

the title the border should display

TitledBorderback to summary
public TitledBorder(Border border, String title, int titleJustification, int titlePosition)

Creates a TitledBorder instance with the specified border, title, title-justification, and title-position.

Parameters
border:Border

the border

title:String

the title the border should display

titleJustification:int

the justification for the title

titlePosition:int

the position for the title

TitledBorderback to summary
public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont)

Creates a TitledBorder instance with the specified border, title, title-justification, title-position, and title-font.

Parameters
border:Border

the border

title:String

the title the border should display

titleJustification:int

the justification for the title

titlePosition:int

the position for the title

titleFont:Font

the font for rendering the title

TitledBorderback to summary
public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont, Color titleColor)

Creates a TitledBorder instance with the specified border, title, title-justification, title-position, title-font, and title-color.

Parameters
border:Border

the border

title:String

the title the border should display

titleJustification:int

the justification for the title

titlePosition:int

the position for the title

titleFont:Font

the font of the title

titleColor:Color

the color of the title

Annotations
@ConstructorProperties:border, title, titleJustification, titlePosition, titleFont, titleColor

Method Detail

getBaselineback to summary
public int getBaseline(Component c, int width, int height)

Overrides javax.swing.border.AbstractBorder.getBaseline.

Returns the baseline.

Parameters
c:Component

Doc from javax.swing.border.AbstractBorder.getBaseline.

Component baseline is being requested for

width:int

Doc from javax.swing.border.AbstractBorder.getBaseline.

the width to get the baseline for

height:int

Doc from javax.swing.border.AbstractBorder.getBaseline.

the height to get the baseline for

Returns:int

Doc from javax.swing.border.AbstractBorder.getBaseline.

the baseline or < 0 indicating there is no reasonable baseline

Exceptions
NullPointerException:
if Component is null
IllegalArgumentException:
if width or height is < 0
Since
1.6
See Also
javax.swing.JComponent#getBaseline(int, int)
getBaselineResizeBehaviorback to summary
public Component.BaselineResizeBehavior getBaselineResizeBehavior(Component c)

Overrides javax.swing.border.AbstractBorder.getBaselineResizeBehavior.

Returns an enum indicating how the baseline of the border changes as the size changes.

Parameters
c:Component

Doc from javax.swing.border.AbstractBorder.getBaselineResizeBehavior.

Component to return baseline resize behavior for

Returns:Component.BaselineResizeBehavior

Doc from javax.swing.border.AbstractBorder.getBaselineResizeBehavior.

an enum indicating how the baseline changes as the border is resized

Exceptions
NullPointerException:
if Component is null
Since
1.6
See Also
javax.swing.JComponent#getBaseline(int, int)
getBorderback to summary
public Border getBorder()

Returns the border of the titled border.

Returns:Border

the border of the titled border

getBorderInsetsback to summary
public Insets getBorderInsets(Component c, Insets insets)

Overrides javax.swing.border.AbstractBorder.getBorderInsets.

Reinitialize the insets parameter with this Border's current Insets.

Parameters
c:Component

the component for which this border insets value applies

insets:Insets

the object to be reinitialized

Returns:Insets

Doc from javax.swing.border.AbstractBorder.getBorderInsets.

the insets object

Exceptions
NullPointerException:
if the specified insets is null
getBorderInsetsback to summary
private static Insets getBorderInsets(Border border, Component c, Insets insets)
getColorback to summary
private Color getColor(Component c)
getFontback to summary
protected Font getFont(Component c)

Returns default font of the titled border.

Parameters
c:Component

the component

Returns:Font

default font of the titled border

getJustificationback to summary
private int getJustification(Component c)
getLabelback to summary
private JLabel getLabel(Component c)
getMinimumSizeback to summary
public Dimension getMinimumSize(Component c)

Returns the minimum dimensions this border requires in order to fully display the border and title.

Parameters
c:Component

the component where this border will be drawn

Returns:Dimension

the Dimension object

getPositionback to summary
private int getPosition()
getTitleback to summary
public String getTitle()

Returns the title of the titled border.

Returns:String

the title of the titled border

getTitleColorback to summary
public Color getTitleColor()

Returns the title-color of the titled border.

Returns:Color

the title-color of the titled border

getTitleFontback to summary
public Font getTitleFont()

Returns the title-font of the titled border.

Returns:Font

the title-font of the titled border

getTitleJustificationback to summary
public int getTitleJustification()

Returns the title-justification of the titled border.

Returns:int

the title-justification of the titled border

getTitlePositionback to summary
public int getTitlePosition()

Returns the title-position of the titled border.

Returns:int

the title-position of the titled border

installPropertyChangeListenersback to summary
private void installPropertyChangeListeners()
isBorderOpaqueback to summary
public boolean isBorderOpaque()

Overrides javax.swing.border.AbstractBorder.isBorderOpaque.

Implements javax.swing.border.Border.isBorderOpaque.

Returns whether or not the border is opaque.

Returns:boolean

Doc from javax.swing.border.AbstractBorder.isBorderOpaque.

false

paintBorderback to summary
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)

Overrides javax.swing.border.AbstractBorder.paintBorder.

Implements javax.swing.border.Border.paintBorder.

Paints the border for the specified component with the specified position and size.

Parameters
c:Component

the component for which this border is being painted

g:Graphics

the paint graphics

x:int

the x position of the painted border

y:int

the y position of the painted border

width:int

the width of the painted border

height:int

the height of the painted border

setBorderback to summary
public void setBorder(Border border)

Sets the border of the titled border.

Parameters
border:Border

the border

setTitleback to summary
public void setTitle(String title)

Sets the title of the titled border.

Parameters
title:String

the title for the border

setTitleColorback to summary
public void setTitleColor(Color titleColor)

Sets the title-color of the titled border.

Parameters
titleColor:Color

the color for the border title

setTitleFontback to summary
public void setTitleFont(Font titleFont)

Sets the title-font of the titled border.

Parameters
titleFont:Font

the font for the border title

setTitleJustificationback to summary
public void setTitleJustification(int titleJustification)

Sets the title-justification of the titled border.

Parameters
titleJustification:int

the justification for the border

setTitlePositionback to summary
public void setTitlePosition(int titlePosition)

Sets the title-position of the titled border.

Parameters
titlePosition:int

the position for the border