java.lang.Object
javax.swing.border.AbstractBorder
javax.swing.border.TitledBorder
- All Implemented Interfaces:
Serializable
,Border
- Direct Known Subclasses:
BorderUIResource.TitledBorderUIResource
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:
- "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 JavaBeans
has been added to the java.beans
package.
Please see XMLEncoder
.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Position the title above the border's bottom line.static final int
Position the title above the border's top line.static final int
Position the title below the border's bottom line.static final int
Position the title below the border's top line.protected Border
The border.static final int
Position the title in the middle of the border's bottom line.static final int
Position title text in the center of the border line.static final int
Use the default justification for the title text.static final int
Use the default vertical orientation for the title text.protected static final int
Space between the border and the component's edgestatic final int
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.static final int
Position title text at the left side of the border line.static final int
Position title text at the right side of the border line.protected static final int
Horizontal inset of text that is left or right justifiedprotected static final int
Space between the border and textprotected String
The title the border should display.protected Color
The color of the title.protected Font
The font for rendering the title.protected int
The justification for the title.protected int
The position for the title.static final int
Position the title in the middle of the border's top line.static final int
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
ConstructorDescriptionTitledBorder
(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. -
Method Summary
Modifier and TypeMethodDescriptionint
getBaseline
(Component c, int width, int height) Returns the baseline.Returns an enum indicating how the baseline of the border changes as the size changes.Returns the border of the titled border.getBorderInsets
(Component c, Insets insets) Reinitialize the insets parameter with this Border's current Insets.protected Font
Returns default font of the titled border.Returns the minimum dimensions this border requires in order to fully display the border and title.getTitle()
Returns the title of the titled border.Returns the title-color of the titled border.Returns the title-font of the titled border.int
Returns the title-justification of the titled border.int
Returns the title-position of the titled border.boolean
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
Sets the border of the titled border.void
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.Methods declared in class javax.swing.border.AbstractBorder
getBorderInsets, getInteriorRectangle, getInteriorRectangle
-
Field Details
-
title
The title the border should display. -
border
The border. -
titlePosition
protected int titlePositionThe position for the title. -
titleJustification
protected int titleJustificationThe justification for the title. -
titleFont
The font for rendering the title. -
titleColor
The color of the title. -
DEFAULT_POSITION
public static final int DEFAULT_POSITIONUse the default vertical orientation for the title text.- See Also:
-
ABOVE_TOP
public static final int ABOVE_TOPPosition the title above the border's top line.- See Also:
-
TOP
public static final int TOPPosition the title in the middle of the border's top line.- See Also:
-
BELOW_TOP
public static final int BELOW_TOPPosition the title below the border's top line.- See Also:
-
ABOVE_BOTTOM
public static final int ABOVE_BOTTOMPosition the title above the border's bottom line.- See Also:
-
BOTTOM
public static final int BOTTOMPosition the title in the middle of the border's bottom line.- See Also:
-
BELOW_BOTTOM
public static final int BELOW_BOTTOMPosition the title below the border's bottom line.- See Also:
-
DEFAULT_JUSTIFICATION
public static final int DEFAULT_JUSTIFICATIONUse the default justification for the title text.- See Also:
-
LEFT
public static final int LEFTPosition title text at the left side of the border line.- See Also:
-
CENTER
public static final int CENTERPosition title text in the center of the border line.- See Also:
-
RIGHT
public static final int RIGHTPosition title text at the right side of the border line.- See Also:
-
LEADING
public static final int LEADINGPosition 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.- See Also:
-
TRAILING
public static final int TRAILINGPosition 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.- See Also:
-
EDGE_SPACING
protected static final int EDGE_SPACINGSpace between the border and the component's edge- See Also:
-
TEXT_SPACING
protected static final int TEXT_SPACINGSpace between the border and text- See Also:
-
TEXT_INSET_H
protected static final int TEXT_INSET_HHorizontal inset of text that is left or right justified- See Also:
-
-
Constructor Details
-
TitledBorder
Creates a TitledBorder instance.- Parameters:
title
- the title the border should display
-
TitledBorder
Creates a TitledBorder instance with the specified border and an empty title.- Parameters:
border
- the border
-
TitledBorder
-
TitledBorder
Creates a TitledBorder instance with the specified border, title, title-justification, and title-position.- Parameters:
border
- the bordertitle
- the title the border should displaytitleJustification
- the justification for the titletitlePosition
- the position for the title
-
TitledBorder
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 bordertitle
- the title the border should displaytitleJustification
- the justification for the titletitlePosition
- the position for the titletitleFont
- the font for rendering the title
-
TitledBorder
@ConstructorProperties({"border","title","titleJustification","titlePosition","titleFont","titleColor"}) 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 bordertitle
- the title the border should displaytitleJustification
- the justification for the titletitlePosition
- the position for the titletitleFont
- the font of the titletitleColor
- the color of the title
-
-
Method Details
-
paintBorder
Paints the border for the specified component with the specified position and size.- Specified by:
paintBorder
in interfaceBorder
- Overrides:
paintBorder
in classAbstractBorder
- Parameters:
c
- the component for which this border is being paintedg
- the paint graphicsx
- the x position of the painted bordery
- the y position of the painted borderwidth
- the width of the painted borderheight
- the height of the painted border
-
getBorderInsets
Reinitialize the insets parameter with this Border's current Insets.- Overrides:
getBorderInsets
in classAbstractBorder
- Parameters:
c
- the component for which this border insets value appliesinsets
- the object to be reinitialized- Returns:
- the
insets
object - Throws:
NullPointerException
- if the specifiedinsets
isnull
-
isBorderOpaque
public boolean isBorderOpaque()Returns whether or not the border is opaque.- Specified by:
isBorderOpaque
in interfaceBorder
- Overrides:
isBorderOpaque
in classAbstractBorder
- Returns:
- false
-
getTitle
Returns the title of the titled border.- Returns:
- the title of the titled border
-
getBorder
Returns the border of the titled border.- Returns:
- the border of the titled border
-
getTitlePosition
public int getTitlePosition()Returns the title-position of the titled border.- Returns:
- the title-position of the titled border
-
getTitleJustification
public int getTitleJustification()Returns the title-justification of the titled border.- Returns:
- the title-justification of the titled border
-
getTitleFont
Returns the title-font of the titled border.- Returns:
- the title-font of the titled border
-
getTitleColor
Returns the title-color of the titled border.- Returns:
- the title-color of the titled border
-
setTitle
Sets the title of the titled border.- Parameters:
title
- the title for the border
-
setBorder
Sets the border of the titled border.- Parameters:
border
- the border
-
setTitlePosition
public void setTitlePosition(int titlePosition) Sets the title-position of the titled border.- Parameters:
titlePosition
- the position for the border
-
setTitleJustification
public void setTitleJustification(int titleJustification) Sets the title-justification of the titled border.- Parameters:
titleJustification
- the justification for the border
-
setTitleFont
Sets the title-font of the titled border.- Parameters:
titleFont
- the font for the border title
-
setTitleColor
Sets the title-color of the titled border.- Parameters:
titleColor
- the color for the border title
-
getMinimumSize
-
getBaseline
Returns the baseline.- Overrides:
getBaseline
in classAbstractBorder
- Parameters:
c
-Component
baseline is being requested forwidth
- the width to get the baseline forheight
- the height to get the baseline for- Returns:
- the baseline or < 0 indicating there is no reasonable baseline
- Throws:
NullPointerException
- ifComponent
isnull
IllegalArgumentException
- if width or height is < 0- Since:
- 1.6
- See Also:
-
getBaselineResizeBehavior
Returns an enum indicating how the baseline of the border changes as the size changes.- Overrides:
getBaselineResizeBehavior
in classAbstractBorder
- Parameters:
c
-Component
to return baseline resize behavior for- Returns:
- an enum indicating how the baseline changes as the border is resized
- Throws:
NullPointerException
- ifComponent
isnull
- Since:
- 1.6
- See Also:
-
getFont
-