public class

TitledBorder

extends AbstractBorder
java.lang.Object
   ↳ javax.swing.border.AbstractBorder
     ↳ javax.swing.border.TitledBorder
Known Direct Subclasses

Class Overview

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

  • "TitledBorder.border"
  • "TitledBorder.font"
  • "TitledBorder.titleColor"

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

Summary

Constants
int ABOVE_BOTTOM Position the title above the border's bottom line.
int ABOVE_TOP Position the title above the border's top line.
int BELOW_BOTTOM Position the title below the border's bottom line.
int BELOW_TOP Position the title below the border's top line.
int BOTTOM Position the title in the middle of the border's bottom line.
int CENTER Position title text in the center of the border line.
int DEFAULT_JUSTIFICATION Use the default justification for the title text.
int DEFAULT_POSITION Use the default vertical orientation for the title text.
int EDGE_SPACING
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.
int LEFT Position title text at the left side of the border line.
int RIGHT Position title text at the right side of the border line.
int TEXT_INSET_H
int TEXT_SPACING
int TOP Position the title in the middle of the border's top line.
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.
Fields
protected Border border
protected String title
protected Color titleColor
protected Font titleFont
protected int titleJustification
protected int titlePosition
Public Constructors
TitledBorder(String title)
Creates a TitledBorder instance.
TitledBorder(Border border)
Creates a TitledBorder instance with the specified border and an empty title.
TitledBorder(Border border, String title)
Creates a TitledBorder instance with the specified border and title.
TitledBorder(Border border, String title, int titleJustification, int titlePosition)
Creates a TitledBorder instance with the specified border, title, title-justification, and title-position.
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.
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.
Public Methods
int getBaseline(Component c, int width, int height)
Returns the baseline.
Component.BaselineResizeBehavior getBaselineResizeBehavior(Component c)
Returns an enum indicating how the baseline of the border changes as the size changes.
Border getBorder()
Returns the border of the titled border.
Insets getBorderInsets(Component c, Insets insets)
Reinitialize the insets parameter with this Border's current Insets.
Insets getBorderInsets(Component c)
Returns the insets of the border.
Dimension getMinimumSize(Component c)
Returns the minimum dimensions this border requires in order to fully display the border and title.
String getTitle()
Returns the title of the titled border.
Color getTitleColor()
Returns the title-color of the titled border.
Font getTitleFont()
Returns the title-font of the titled border.
int getTitleJustification()
Returns the title-justification of the titled border.
int getTitlePosition()
Returns the title-position of the titled border.
boolean isBorderOpaque()
Returns whether or not the border is opaque.
void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
Paints the border for the specified component with the specified position and size.
void setBorder(Border border)
Sets the border of the titled border.
void setTitle(String title)
Sets the title of the titled border.
void setTitleColor(Color titleColor)
Sets the title-color of the titled border.
void setTitleFont(Font titleFont)
Sets the title-font of the titled border.
void setTitleJustification(int titleJustification)
Sets the title-justification of the titled border.
void setTitlePosition(int titlePosition)
Sets the title-position of the titled border.
Protected Methods
Font getFont(Component c)
[Expand]
Inherited Methods
From class javax.swing.border.AbstractBorder
From class java.lang.Object
From interface javax.swing.border.Border

Constants

public static final int ABOVE_BOTTOM

Position the title above the border's bottom line.

Constant Value: 4 (0x00000004)

public static final int ABOVE_TOP

Position the title above the border's top line.

Constant Value: 1 (0x00000001)

public static final int BELOW_BOTTOM

Position the title below the border's bottom line.

Constant Value: 6 (0x00000006)

public static final int BELOW_TOP

Position the title below the border's top line.

Constant Value: 3 (0x00000003)

public static final int BOTTOM

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

Constant Value: 5 (0x00000005)

public static final int CENTER

Position title text in the center of the border line.

Constant Value: 2 (0x00000002)

public static final int DEFAULT_JUSTIFICATION

Use the default justification for the title text.

Constant Value: 0 (0x00000000)

public static final int DEFAULT_POSITION

Use the default vertical orientation for the title text.

Constant Value: 0 (0x00000000)

protected static final int EDGE_SPACING

Constant Value: 2 (0x00000002)

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.

Constant Value: 4 (0x00000004)

public static final int LEFT

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

Constant Value: 1 (0x00000001)

public static final int RIGHT

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

Constant Value: 3 (0x00000003)

protected static final int TEXT_INSET_H

Constant Value: 5 (0x00000005)

protected static final int TEXT_SPACING

Constant Value: 2 (0x00000002)

public static final int TOP

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

Constant Value: 2 (0x00000002)

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.

Constant Value: 5 (0x00000005)

Fields

protected Border border

protected String title

protected Color titleColor

protected Font titleFont

protected int titleJustification

protected int titlePosition

Public Constructors

public TitledBorder (String title)

Creates a TitledBorder instance.

Parameters
title the title the border should display

public TitledBorder (Border border)

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

Parameters
border the border

public TitledBorder (Border border, String title)

Creates a TitledBorder instance with the specified border and title.

Parameters
border the border
title the title the border should display

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 the border
title the title the border should display
titleJustification the justification for the title
titlePosition the position for the title

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 the border
title the title the border should display
titleJustification the justification for the title
titlePosition the position for the title
titleFont the font for rendering the title

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 the border
title the title the border should display
titleJustification the justification for the title
titlePosition the position for the title
titleFont the font of the title
titleColor the color of the title

Public Methods

public int getBaseline (Component c, int width, int height)

Returns the baseline.

Parameters
c Component baseline is being requested for
width the width to get the baseline for
height the height to get the baseline for
Returns
  • the baseline or < 0 indicating there is no reasonable baseline

public Component.BaselineResizeBehavior getBaselineResizeBehavior (Component c)

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

Parameters
c Component to return baseline resize behavior for
Returns
  • an enum indicating how the baseline changes as the border is resized

public Border getBorder ()

Returns the border of the titled border.

public Insets getBorderInsets (Component c, Insets insets)

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

Parameters
c the component for which this border insets value applies
insets the object to be reinitialized
Returns
  • the insets object

public Insets getBorderInsets (Component c)

Returns the insets of the border.

Parameters
c the component for which this border insets value applies
Returns
  • the new Insets object initialized to 0

public Dimension getMinimumSize (Component c)

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

Parameters
c the component where this border will be drawn

public String getTitle ()

Returns the title of the titled border.

public Color getTitleColor ()

Returns the title-color of the titled border.

public Font getTitleFont ()

Returns the title-font of the titled border.

public int getTitleJustification ()

Returns the title-justification of the titled border.

public int getTitlePosition ()

Returns the title-position of the titled border.

public boolean isBorderOpaque ()

Returns whether or not the border is opaque.

Returns
  • false

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

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

Parameters
c the component for which this border is being painted
g the paint graphics
x the x position of the painted border
y the y position of the painted border
width the width of the painted border
height the height of the painted border

public void setBorder (Border border)

Sets the border of the titled border.

Parameters
border the border

public void setTitle (String title)

Sets the title of the titled border. param title the title for the border

public void setTitleColor (Color titleColor)

Sets the title-color of the titled border.

Parameters
titleColor the color for the border title

public void setTitleFont (Font titleFont)

Sets the title-font of the titled border.

Parameters
titleFont the font for the border title

public void setTitleJustification (int titleJustification)

Sets the title-justification of the titled border.

Parameters
titleJustification the justification for the border

public void setTitlePosition (int titlePosition)

Sets the title-position of the titled border.

Parameters
titlePosition the position for the border

Protected Methods

protected Font getFont (Component c)