模块 java.desktop

类 TitledBorder

java.lang.Object
javax.swing.border.AbstractBorder
javax.swing.border.TitledBorder
所有已实现的接口:
Serializable , Border
已知子类:
BorderUIResource.TitledBorderUIResource

public class TitledBorder extends AbstractBorder
通过在指定位置和对齐方式添加字符串标题实现任意边框的类。

如果边框、字体或颜色属性值未在构造方法中或通过调用适当的设置方法指定,则属性值将由当前外观定义,使用默认表中的以下属性名称:

  • “TitledBorder.border”
  • “TitledBorder.font”
  • "TitledBorder.titleColor"

Warning: 此类的序列化对象将与未来的 Swing 版本不兼容。当前的序列化支持适用于运行相同版本 Swing 的应用程序之间的短期存储或 RMI。从 1.4 开始,对所有 JavaBeans 的长期存储的支持已添加到 java.beans 包中。请参阅 XMLEncoder

  • 字段详细信息

    • 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
      为标题文本使用默认的垂直方向。
      参见:
    • ABOVE_TOP

      public static final int ABOVE_TOP
      将标题置于边框顶线之上。
      参见:
    • TOP

      public static final int TOP
      将标题放在边框顶行的中间。
      参见:
    • BELOW_TOP

      public static final int BELOW_TOP
      将标题置于边框顶线下方。
      参见:
    • ABOVE_BOTTOM

      public static final int ABOVE_BOTTOM
      将标题置于边框底线上方。
      参见:
    • BOTTOM

      public static final int BOTTOM
      将标题放在边框底线的中间。
      参见:
    • BELOW_BOTTOM

      public static final int BELOW_BOTTOM
      将标题置于边框底线下方。
      参见:
    • DEFAULT_JUSTIFICATION

      public static final int DEFAULT_JUSTIFICATION
      使用标题文本的默认对齐方式。
      参见:
    • LEFT

      public static final int LEFT
      将标题文本定位在边框线的左侧。
      参见:
    • CENTER

      public static final int CENTER
      将标题文本定位在边框线的中心。
      参见:
    • LEADING

      public static final int LEADING
      对于从左到右的方向,将标题文本定位在边界线的左侧,对于从右到左的方向,定位在边界线的右侧。
      参见:
    • TRAILING

      public static final int TRAILING
      对于从左到右的方向,将标题文本定位在边界线的右侧,对于从右到左的方向,定位在边界线的左侧。
      参见:
    • EDGE_SPACING

      protected static final int EDGE_SPACING
      边框和组件边缘之间的空间
      参见:
    • TEXT_SPACING

      protected static final int TEXT_SPACING
      边框和文本之间的空间
      参见:
    • TEXT_INSET_H

      protected static final int TEXT_INSET_H
      左对齐或右对齐文本的水平插入
      参见:
  • 构造方法详细信息

    • TitledBorder

      public TitledBorder(String  title)
      创建一个 TitledBorder 实例。
      参数:
      title - 边框应显示的标题
    • TitledBorder

      public TitledBorder(Border  border)
      创建具有指定边框和空标题的 TitledBorder 实例。
      参数:
      border - 边框
    • TitledBorder

      public TitledBorder(Border  border, String  title)
      创建具有指定边框和标题的 TitledBorder 实例。
      参数:
      border - 边框
      title - 边框应显示的标题
    • TitledBorder

      public TitledBorder(Border  border, String  title, int titleJustification, int titlePosition)
      创建具有指定边框、标题、标题对齐和标题位置的 TitledBorder 实例。
      参数:
      border - 边框
      title - 边框应显示的标题
      titleJustification - 标题的理由
      titlePosition - 标题的位置
    • TitledBorder

      public TitledBorder(Border  border, String  title, int titleJustification, int titlePosition, Font  titleFont)
      创建具有指定边框、标题、标题对齐、标题位置和标题字体的 TitledBorder 实例。
      参数:
      border - 边框
      title - 边框应显示的标题
      titleJustification - 标题的理由
      titlePosition - 标题的位置
      titleFont - 渲染标题的字体
    • TitledBorder

      @ConstructorProperties ({"border","title","titleJustification","titlePosition","titleFont","titleColor"}) public TitledBorder(Border  border, String  title, int titleJustification, int titlePosition, Font  titleFont, Color  titleColor)
      创建具有指定边框、标题、标题对齐、标题位置、标题字体和标题颜色的 TitledBorder 实例。
      参数:
      border - 边框
      title - 边框应显示的标题
      titleJustification - 标题的理由
      titlePosition - 标题的位置
      titleFont - 标题的字体
      titleColor - 标题的颜色
  • 方法详情

    • paintBorder

      public void paintBorder(Component  c, Graphics  g, int x, int y, int width, int height)
      使用指定的位置和大小绘制指定组件的边框。
      指定者:
      paintBorder 在接口 Border
      重写:
      paintBorder 在类 AbstractBorder
      参数:
      c - 为其绘制边框的组件
      g - 油漆图形
      x - 绘制边框的 x 位置
      y - 绘制边框的 y 位置
      width - 绘制边框的宽度
      height - 绘制边框的高度
    • getBorderInsets

      public Insets  getBorderInsets(Component  c, Insets  insets)
      使用此边框的当前 Insets 重新初始化 insets 参数。
      重写:
      getBorderInsets 在类 AbstractBorder
      参数:
      c - 此边框插入值适用的组件
      insets - 要重新初始化的对象
      返回:
      insets 对象
      抛出:
      NullPointerException - 如果指定的 insetsnull
    • isBorderOpaque

      public boolean isBorderOpaque()
      返回边框是否不透明。
      指定者:
      isBorderOpaque 在接口 Border
      重写:
      isBorderOpaque 在类 AbstractBorder
      返回:
      false
    • getTitle

      public String  getTitle()
      返回带标题的边框的标题。
      返回:
      标题边框的标题
    • getBorder

      public Border  getBorder()
      返回标题边框的边框。
      返回:
      标题边框的边框
    • getTitlePosition

      public int getTitlePosition()
      返回标题边框的标题位置。
      返回:
      标题边框的标题位置
    • getTitleJustification

      public int getTitleJustification()
      返回标题边框的标题对齐。
      返回:
      标题边框的标题对齐
    • getTitleFont

      public Font  getTitleFont()
      返回标题边框的标题字体。
      返回:
      标题边框的标题字体
    • getTitleColor

      public Color  getTitleColor()
      返回标题边框的标题颜色。
      返回:
      标题边框的标题颜色
    • setTitle

      public void setTitle(String  title)
      设置带标题的边框的标题。
      参数:
      title - 边框的标题
    • setBorder

      public void setBorder(Border  border)
      设置标题边框的边框。
      参数:
      border - 边框
    • setTitlePosition

      public void setTitlePosition(int titlePosition)
      设置标题边框的标题位置。
      参数:
      titlePosition - 边框的位置
    • setTitleJustification

      public void setTitleJustification(int titleJustification)
      设置标题边框的标题对齐。
      参数:
      titleJustification - 边界的理由
    • setTitleFont

      public void setTitleFont(Font  titleFont)
      设置标题边框的标题字体。
      参数:
      titleFont - 边框标题的字体
    • setTitleColor

      public void setTitleColor(Color  titleColor)
      设置标题边框的标题颜色。
      参数:
      titleColor - 边框标题的颜色
    • getMinimumSize

      public Dimension  getMinimumSize(Component  c)
      返回此边框为了完全显示边框和标题所需的最小尺寸。
      参数:
      c - 将绘制此边框的组件
      返回:
      Dimension 对象
    • getBaseline

      public int getBaseline(Component  c, int width, int height)
      返回基线。
      重写:
      getBaseline 在类 AbstractBorder
      参数:
      c - Component 正在请求基线
      width - 获取基线的宽度
      height - 获取基线的高度
      返回:
      基线或 < 0 表示没有合理的基线
      抛出:
      NullPointerException - 如果 Componentnull
      IllegalArgumentException - 如果宽度或高度 < 0
      自从:
      1.6
      参见:
    • getBaselineResizeBehavior

      public Component.BaselineResizeBehavior  getBaselineResizeBehavior(Component  c)
      返回一个枚举,指示边框的基线如何随着大小的变化而变化。
      重写:
      getBaselineResizeBehavior 在类 AbstractBorder
      参数:
      c - Component 返回基线调整大小行为
      返回:
      一个枚举,指示基线如何随着边框的大小调整而变化
      抛出:
      NullPointerException - 如果 Componentnull
      自从:
      1.6
      参见:
    • getFont

      protected Font  getFont(Component  c)
      返回标题边框的默认字体。
      参数:
      c - 组件
      返回:
      标题边框的默认字体