模块 java.desktop
 java.awt

枚举类枚举类 Component.BaselineResizeBehavior

java.lang.Object
java.lang.Enum <Component.BaselineResizeBehavior >
java.awt.Component.BaselineResizeBehavior
所有已实现的接口:
Serializable , Comparable<Component.BaselineResizeBehavior> , Constable
封闭类:
Component

public static enum Component.BaselineResizeBehavior extends Enum <Component.BaselineResizeBehavior >
组件基线随大小变化而变化的常见方式的枚举。基线大小调整行为主要用于需要了解基线位置如何随组件大小变化而变化的布局管理器。通常,基线调整大小行为对于大于或等于最小大小(实际最小大小;不是开发人员指定的最小大小)的大小有效。对于小于最小尺寸的尺寸,基线可能会以不同于基线调整大小行为指示的方式发生变化。同样,随着大小接近 Integer.MAX_VALUE 和/或 Short.MAX_VALUE,基线可能会以基线调整大小行为指示的方式以外的方式发生变化。
自从:
1.6
参见:
  • 枚举常量详细信息

    • CONSTANT_ASCENT

      public static final Component.BaselineResizeBehavior  CONSTANT_ASCENT
      表示基线相对于 y 原点保持固定。也就是说,无论高度或宽度如何,getBaseline 都会返回相同的值。例如,包含垂直对齐方式为 TOP 的非空文本的 JLabel 的基线类型应为 CONSTANT_ASCENT
    • CONSTANT_DESCENT

      public static final Component.BaselineResizeBehavior  CONSTANT_DESCENT
      表示基线相对于高度保持固定,并且不会随着宽度的变化而改变。也就是说,对于任何高度 H,H 和 getBaseline(w, H) 之间的差异是相同的。例如,包含垂直对齐方式为 BOTTOM 的非空文本的 JLabel 的基线类型应为 CONSTANT_DESCENT
    • CENTER_OFFSET

      public static final Component.BaselineResizeBehavior  CENTER_OFFSET
      指示基线与组件中心保持固定距离。也就是说,对于任何高度 H,getBaseline(w, H)H / 2 之间的差异是相同的(正负一取决于舍入误差)。

      由于可能会出现舍入错误,建议您询问具有两个连续高度的基线,并使用返回值来确定是否需要在计算中补 1。下面显示了如何计算任何高度的基线:

        Dimension preferredSize = component.getPreferredSize();
        int baseline = getBaseline(preferredSize.width,
                     preferredSize.height);
        int nextBaseline = getBaseline(preferredSize.width,
                       preferredSize.height + 1);
        // Amount to add to height when calculating where baseline
        // lands for a particular height:
        int padding = 0;
        // Where the baseline is relative to the mid point
        int baselineOffset = baseline - height / 2;
        if (preferredSize.height % 2 == 0 &&
          baseline != nextBaseline) {
          padding = 1;
        }
        else if (preferredSize.height % 2 == 1 &&
            baseline == nextBaseline) {
          baselineOffset--;
          padding = 1;
        }
        // The following calculates where the baseline lands for
        // the height z:
        int calculatedBaseline = (z + padding) / 2 + baselineOffset;
       
    • OTHER

      public static final Component.BaselineResizeBehavior  OTHER
      指示基线调整大小行为不能使用任何其他常量表示。这也可能表明基线随组件的宽度而变化。这也由没有基线的组件返回。
  • 方法详情

    • values

      public static Component.BaselineResizeBehavior [] values()
      返回一个数组,其中包含此枚举类的常量,按照它们声明的顺序排列。
      返回:
      包含此枚举类常量的数组,按照它们声明的顺序排列
    • valueOf

      public static Component.BaselineResizeBehavior  valueOf(String  name)
      返回具有指定名称的此类的枚举常量。字符串必须匹配确切地用于在此类中声明枚举常量的标识符。 (不允许使用无关的空白字符。)
      参数:
      name - 要返回的枚举常量的名称。
      返回:
      具有指定名称的枚举常量
      抛出:
      IllegalArgumentException - 如果此枚举类没有具有指定名称的常量
      NullPointerException - 如果参数为空