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:
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
.
protected String title
protected Border border
protected int titlePosition
protected int titleJustification
protected Font titleFont
protected Color titleColor
public static final int DEFAULT_POSITION
Use the default vertical orientation for the title text.
public static final int ABOVE_TOP
Position the title above the border's top line.
public static final int TOP
Position the title in the middle of the border's top line.
public static final int BELOW_TOP
Position the title below the border's top line.
public static final int ABOVE_BOTTOM
Position the title above the border's bottom line.
public static final int BOTTOM
Position the title in the middle of the border's bottom line.
public static final int BELOW_BOTTOM
Position the title below the border's bottom line.
public static final int DEFAULT_JUSTIFICATION
Use the default justification for the title text.
public static final int LEFT
Position title text at the left side of the border line.
public static final int CENTER
Position title text in the center of the border line.
public static final int RIGHT
Position title text at the right side of the border line.
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 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.
protected static final int EDGE_SPACING
protected static final int TEXT_SPACING
protected static final int TEXT_INSET_H
public TitledBorder(String title)
Creates a TitledBorder instance.
title
- the title the border should displaypublic TitledBorder(Border border)
Creates a TitledBorder instance with the specified border and an empty title.
border
- the borderpublic TitledBorder(Border border, String title)
Creates a TitledBorder instance with the specified border and title.
border
- the bordertitle
- the title the border should displaypublic TitledBorder(Border border, String title, int titleJustification, int titlePosition)
Creates a TitledBorder instance with the specified border, title, title-justification, and title-position.
border
- the bordertitle
- the title the border should displaytitleJustification
- the justification for the titletitlePosition
- the position for the titlepublic 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.
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@ConstructorProperties(value={"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.
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 titlepublic 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.
paintBorder
in interface Border
paintBorder
in class AbstractBorder
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 borderpublic Insets getBorderInsets(Component c, Insets insets)
Reinitialize the insets parameter with this Border's current Insets.
getBorderInsets
in class AbstractBorder
c
- the component for which this border insets value appliesinsets
- the object to be reinitializedinsets
objectpublic boolean isBorderOpaque()
Returns whether or not the border is opaque.
isBorderOpaque
in interface Border
isBorderOpaque
in class AbstractBorder
public String getTitle()
Returns the title of the titled border.
public Border getBorder()
Returns the border of the titled border.
public int getTitlePosition()
Returns the title-position of the titled border.
public int getTitleJustification()
Returns the title-justification of the titled border.
public Font getTitleFont()
Returns the title-font of the titled border.
public Color getTitleColor()
Returns the title-color of the titled border.
public void setTitle(String title)
Sets the title of the titled border.
title
- the title for the borderpublic void setBorder(Border border)
Sets the border of the titled border.
border
- the borderpublic void setTitlePosition(int titlePosition)
Sets the title-position of the titled border.
titlePosition
- the position for the borderpublic void setTitleJustification(int titleJustification)
Sets the title-justification of the titled border.
titleJustification
- the justification for the borderpublic void setTitleFont(Font titleFont)
Sets the title-font of the titled border.
titleFont
- the font for the border titlepublic void setTitleColor(Color titleColor)
Sets the title-color of the titled border.
titleColor
- the color for the border titlepublic Dimension getMinimumSize(Component c)
Returns the minimum dimensions this border requires in order to fully display the border and title.
c
- the component where this border will be drawnDimension
objectpublic int getBaseline(Component c, int width, int height)
Returns the baseline.
getBaseline
in class AbstractBorder
c
- Component
baseline is being requested forwidth
- the width to get the baseline forheight
- the height to get the baseline forNullPointerException
IllegalArgumentException
- if width or height is < 0JComponent.getBaseline(int, int)
public Component.BaselineResizeBehavior getBaselineResizeBehavior(Component c)
Returns an enum indicating how the baseline of the border changes as the size changes.
getBaselineResizeBehavior
in class AbstractBorder
c
- Component
to return baseline resize behavior forNullPointerException
JComponent.getBaseline(int, int)
protected Font getFont(Component c)
© 1993–2017, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.