Class TitledBorder
- All Implemented Interfaces:
-
Serializable
,Border
- Direct Known Subclasses:
BorderUIResource.TitledBorderUIResource
public class TitledBorder extends AbstractBorder
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 Type | Field | Description |
---|---|---|
static final int |
ABOVE_BOTTOM |
Position the title above the border's bottom line. |
static final int |
ABOVE_TOP |
Position the title above the border's top line. |
static final int |
BELOW_BOTTOM |
Position the title below the border's bottom line. |
static final int |
BELOW_TOP |
Position the title below the border's top line. |
protected Border |
border |
The border. |
static final int |
BOTTOM |
Position the title in the middle of the border's bottom line. |
static final int |
CENTER |
Position title text in the center of the border line. |
static final int |
DEFAULT_JUSTIFICATION |
Use the default justification for the title text. |
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 |
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. |
static final int |
LEFT |
Position title text at the left side of the border line. |
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. |
static final int |
TOP |
Position the title in the middle of the border's top line. |
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
Constructor | Description |
---|---|
TitledBorder |
Creates a TitledBorder instance. |
TitledBorder |
Creates a TitledBorder instance with the specified border and an empty title. |
TitledBorder |
Creates a TitledBorder instance with the specified border and title. |
TitledBorder |
Creates a TitledBorder instance with the specified border, title, title-justification, and title-position. |
TitledBorder |
Creates a TitledBorder instance with the specified border, title, title-justification, title-position, and title-font. |
TitledBorder |
Creates a TitledBorder instance with the specified border, title, title-justification, title-position, title-font, and title-color. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
int |
getBaseline |
Returns the baseline. |
Component.BaselineResizeBehavior |
getBaselineResizeBehavior |
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 |
Reinitialize the insets parameter with this Border's current Insets. |
protected Font |
getFont |
Returns default font of the titled border. |
Dimension |
getMinimumSize |
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 |
Paints the border for the specified component with the specified position and size. |
void |
setBorder |
Sets the border of the titled border. |
void |
setTitle |
Sets the title of the titled border. |
void |
setTitleColor |
Sets the title-color of the titled border. |
void |
setTitleFont |
Sets the title-font of the titled border. |
void |
setTitleJustification |
Sets the title-justification of the titled border. |
void |
setTitlePosition |
Sets the title-position of the titled border. |
Methods declared in class javax.swing.border.AbstractBorder
getBorderInsets, getInteriorRectangle, getInteriorRectangle
Field Details
title
protected String title
border
protected Border border
titlePosition
protected int titlePosition
titleJustification
protected int titleJustification
titleFont
protected Font titleFont
titleColor
protected Color titleColor
DEFAULT_POSITION
public static final int DEFAULT_POSITION
- See Also:
ABOVE_TOP
public static final int ABOVE_TOP
- See Also:
TOP
public static final int TOP
- See Also:
BELOW_TOP
public static final int BELOW_TOP
- See Also:
ABOVE_BOTTOM
public static final int ABOVE_BOTTOM
- See Also:
BOTTOM
public static final int BOTTOM
- See Also:
BELOW_BOTTOM
public static final int BELOW_BOTTOM
- See Also:
DEFAULT_JUSTIFICATION
public static final int DEFAULT_JUSTIFICATION
- See Also:
LEFT
public static final int LEFT
- See Also:
CENTER
public static final int CENTER
- See Also:
RIGHT
public static final int RIGHT
- See Also:
LEADING
public static final int LEADING
- See Also:
TRAILING
public static final int TRAILING
- See Also:
EDGE_SPACING
protected static final int EDGE_SPACING
- See Also:
TEXT_SPACING
protected static final int TEXT_SPACING
- See Also:
TEXT_INSET_H
protected static final int TEXT_INSET_H
- See Also:
Constructor Details
TitledBorder
public TitledBorder(String title)
- Parameters:
-
title
- the title the border should display
TitledBorder
public TitledBorder(Border border)
- Parameters:
-
border
- the border
TitledBorder
public TitledBorder(Border border, String title)
- Parameters:
-
border
- the border -
title
- the title the border should display
TitledBorder
public TitledBorder(Border border, String title, int titleJustification, int titlePosition)
- Parameters:
-
border
- the border -
title
- the title the border should display -
titleJustification
- the justification for the title -
titlePosition
- the position for the title
TitledBorder
public TitledBorder(Border border, String title, int titleJustification, int titlePosition, Font titleFont)
- 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)
- 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
paintBorder
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height)
- Specified by:
-
paintBorder
in interfaceBorder
- Overrides:
-
paintBorder
in classAbstractBorder
- 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
getBorderInsets
public Insets getBorderInsets(Component c, Insets insets)
- Overrides:
-
getBorderInsets
in classAbstractBorder
- Parameters:
-
c
- the component for which this border insets value applies -
insets
- the object to be reinitialized - Returns:
- the
insets
object
isBorderOpaque
public boolean isBorderOpaque()
- Specified by:
-
isBorderOpaque
in interfaceBorder
- Overrides:
-
isBorderOpaque
in classAbstractBorder
- Returns:
- false
getTitle
public String getTitle()
- Returns:
- the title of the titled border
getBorder
public Border getBorder()
- Returns:
- the border of the titled border
getTitlePosition
public int getTitlePosition()
- Returns:
- the title-position of the titled border
getTitleJustification
public int getTitleJustification()
- Returns:
- the title-justification of the titled border
getTitleFont
public Font getTitleFont()
- Returns:
- the title-font of the titled border
getTitleColor
public Color getTitleColor()
- Returns:
- the title-color of the titled border
setTitle
public void setTitle(String title)
- Parameters:
-
title
- the title for the border
setBorder
public void setBorder(Border border)
- Parameters:
-
border
- the border
setTitlePosition
public void setTitlePosition(int titlePosition)
- Parameters:
-
titlePosition
- the position for the border
setTitleJustification
public void setTitleJustification(int titleJustification)
- Parameters:
-
titleJustification
- the justification for the border
setTitleFont
public void setTitleFont(Font titleFont)
- Parameters:
-
titleFont
- the font for the border title
setTitleColor
public void setTitleColor(Color titleColor)
- Parameters:
-
titleColor
- the color for the border title
getMinimumSize
public Dimension getMinimumSize(Component c)
- Parameters:
-
c
- the component where this border will be drawn - Returns:
- the
Dimension
object
getBaseline
public int getBaseline(Component c, int width, int height)
- Overrides:
-
getBaseline
in classAbstractBorder
- 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
- Throws:
NullPointerException
-
IllegalArgumentException
- if width or height is < 0 - Since:
- 1.6
- See Also:
getBaselineResizeBehavior
public Component.BaselineResizeBehavior getBaselineResizeBehavior(Component c)
- 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
- Since:
- 1.6
- See Also:
getFont
protected Font getFont(Component c)
- Parameters:
-
c
- the component - Returns:
- default font of the titled border
© 1993, 2021, 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.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/border/TitledBorder.html