java.lang.Object
javax.swing.border.AbstractBorder
javax.swing.border.TitledBorder
- All Implemented Interfaces:
- Serializable,- Border
- Direct Known Subclasses:
- BorderUIResource.TitledBorderUIResource
public class TitledBorder extends AbstractBorder
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 SummaryFields Modifier and Type Field Description static intABOVE_BOTTOMPosition the title above the border's bottom line.static intABOVE_TOPPosition the title above the border's top line.static intBELOW_BOTTOMPosition the title below the border's bottom line.static intBELOW_TOPPosition the title below the border's top line.protected BorderborderThe border.static intBOTTOMPosition the title in the middle of the border's bottom line.static intCENTERPosition title text in the center of the border line.static intDEFAULT_JUSTIFICATIONUse the default justification for the title text.static intDEFAULT_POSITIONUse the default vertical orientation for the title text.protected static intEDGE_SPACINGSpace between the border and the component's edgestatic intLEADINGPosition 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 intLEFTPosition title text at the left side of the border line.static intRIGHTPosition title text at the right side of the border line.protected static intTEXT_INSET_HHorizontal inset of text that is left or right justifiedprotected static intTEXT_SPACINGSpace between the border and textprotected StringtitleThe title the border should display.protected ColortitleColorThe color of the title.protected FonttitleFontThe font for rendering the title.protected inttitleJustificationThe justification for the title.protected inttitlePositionThe position for the title.static intTOPPosition the title in the middle of the border's top line.static intTRAILINGPosition 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 SummaryConstructors Constructor Description 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.
- 
Method SummaryModifier and Type Method Description intgetBaseline(Component c, int width, int height)Returns the baseline.Component.BaselineResizeBehaviorgetBaselineResizeBehavior(Component c)Returns an enum indicating how the baseline of the border changes as the size changes.BordergetBorder()Returns the border of the titled border.InsetsgetBorderInsets(Component c, Insets insets)Reinitialize the insets parameter with this Border's current Insets.protected FontgetFont(Component c)Returns default font of the titled border.DimensiongetMinimumSize(Component c)Returns the minimum dimensions this border requires in order to fully display the border and title.StringgetTitle()Returns the title of the titled border.ColorgetTitleColor()Returns the title-color of the titled border.FontgetTitleFont()Returns the title-font of the titled border.intgetTitleJustification()Returns the title-justification of the titled border.intgetTitlePosition()Returns the title-position of the titled border.booleanisBorderOpaque()Returns whether or not the border is opaque.voidpaintBorder(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.voidsetBorder(Border border)Sets the border of the titled border.voidsetTitle(String title)Sets the title of the titled border.voidsetTitleColor(Color titleColor)Sets the title-color of the titled border.voidsetTitleFont(Font titleFont)Sets the title-font of the titled border.voidsetTitleJustification(int titleJustification)Sets the title-justification of the titled border.voidsetTitlePosition(int titlePosition)Sets the title-position of the titled border.Methods declared in class javax.swing.border.AbstractBordergetBorderInsets, getInteriorRectangle, getInteriorRectangle
- 
Field Details- 
titleThe title the border should display.
- 
borderThe border.
- 
titlePositionprotected int titlePositionThe position for the title.
- 
titleJustificationprotected int titleJustificationThe justification for the title.
- 
titleFontThe font for rendering the title.
- 
titleColorThe color of the title.
- 
DEFAULT_POSITIONpublic static final int DEFAULT_POSITIONUse the default vertical orientation for the title text.- See Also:
- Constant Field Values
 
- 
ABOVE_TOPpublic static final int ABOVE_TOPPosition the title above the border's top line.- See Also:
- Constant Field Values
 
- 
TOPpublic static final int TOPPosition the title in the middle of the border's top line.- See Also:
- Constant Field Values
 
- 
BELOW_TOPpublic static final int BELOW_TOPPosition the title below the border's top line.- See Also:
- Constant Field Values
 
- 
ABOVE_BOTTOMpublic static final int ABOVE_BOTTOMPosition the title above the border's bottom line.- See Also:
- Constant Field Values
 
- 
BOTTOMpublic static final int BOTTOMPosition the title in the middle of the border's bottom line.- See Also:
- Constant Field Values
 
- 
BELOW_BOTTOMpublic static final int BELOW_BOTTOMPosition the title below the border's bottom line.- See Also:
- Constant Field Values
 
- 
DEFAULT_JUSTIFICATIONpublic static final int DEFAULT_JUSTIFICATIONUse the default justification for the title text.- See Also:
- Constant Field Values
 
- 
LEFTpublic static final int LEFTPosition title text at the left side of the border line.- See Also:
- Constant Field Values
 
- 
CENTERpublic static final int CENTERPosition title text in the center of the border line.- See Also:
- Constant Field Values
 
- 
RIGHTpublic static final int RIGHTPosition title text at the right side of the border line.- See Also:
- Constant Field Values
 
- 
LEADINGpublic 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:
- Constant Field Values
 
- 
TRAILINGpublic 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:
- Constant Field Values
 
- 
EDGE_SPACINGprotected static final int EDGE_SPACINGSpace between the border and the component's edge- See Also:
- Constant Field Values
 
- 
TEXT_SPACINGprotected static final int TEXT_SPACINGSpace between the border and text- See Also:
- Constant Field Values
 
- 
TEXT_INSET_Hprotected static final int TEXT_INSET_HHorizontal inset of text that is left or right justified- See Also:
- Constant Field Values
 
 
- 
- 
Constructor Details- 
TitledBorderCreates a TitledBorder instance.- Parameters:
- title- the title the border should display
 
- 
TitledBorderCreates a TitledBorder instance with the specified border and an empty title.- Parameters:
- border- the border
 
- 
TitledBorderCreates a TitledBorder instance with the specified border and title.- Parameters:
- border- the border
- title- the title the border should display
 
- 
TitledBorderCreates 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
 
- 
TitledBorderpublic 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
 
- 
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 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
 
 
- 
- 
Method Details- 
paintBorderPaints the border for the specified component with the specified position and size.- Specified by:
- paintBorderin interface- Border
- Overrides:
- paintBorderin class- AbstractBorder
- 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
 
- 
getBorderInsetsReinitialize the insets parameter with this Border's current Insets.- Overrides:
- getBorderInsetsin class- AbstractBorder
- Parameters:
- c- the component for which this border insets value applies
- insets- the object to be reinitialized
- Returns:
- the insetsobject
 
- 
isBorderOpaquepublic boolean isBorderOpaque()Returns whether or not the border is opaque.- Specified by:
- isBorderOpaquein interface- Border
- Overrides:
- isBorderOpaquein class- AbstractBorder
- Returns:
- false
 
- 
getTitleReturns the title of the titled border.- Returns:
- the title of the titled border
 
- 
getBorderReturns the border of the titled border.- Returns:
- the border of the titled border
 
- 
getTitlePositionpublic int getTitlePosition()Returns the title-position of the titled border.- Returns:
- the title-position of the titled border
 
- 
getTitleJustificationpublic int getTitleJustification()Returns the title-justification of the titled border.- Returns:
- the title-justification of the titled border
 
- 
getTitleFontReturns the title-font of the titled border.- Returns:
- the title-font of the titled border
 
- 
getTitleColorReturns the title-color of the titled border.- Returns:
- the title-color of the titled border
 
- 
setTitleSets the title of the titled border.- Parameters:
- title- the title for the border
 
- 
setBorderSets the border of the titled border.- Parameters:
- border- the border
 
- 
setTitlePositionpublic void setTitlePosition(int titlePosition)Sets the title-position of the titled border.- Parameters:
- titlePosition- the position for the border
 
- 
setTitleJustificationpublic void setTitleJustification(int titleJustification)Sets the title-justification of the titled border.- Parameters:
- titleJustification- the justification for the border
 
- 
setTitleFontSets the title-font of the titled border.- Parameters:
- titleFont- the font for the border title
 
- 
setTitleColorSets the title-color of the titled border.- Parameters:
- titleColor- the color for the border title
 
- 
getMinimumSizeReturns 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
- Returns:
- the Dimensionobject
 
- 
getBaselineReturns the baseline.- Overrides:
- getBaselinein class- AbstractBorder
- Parameters:
- c-- Componentbaseline 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
- Throws:
- NullPointerException
- IllegalArgumentException- if width or height is < 0
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
- 
getBaselineResizeBehaviorReturns an enum indicating how the baseline of the border changes as the size changes.- Overrides:
- getBaselineResizeBehaviorin class- AbstractBorder
- Parameters:
- c-- Componentto return baseline resize behavior for
- Returns:
- an enum indicating how the baseline changes as the border is resized
- Throws:
- NullPointerException
- Since:
- 1.6
- See Also:
- JComponent.getBaseline(int, int)
 
- 
getFontReturns default font of the titled border.- Parameters:
- c- the component
- Returns:
- default font of the titled border
 
 
-