Serializable
, Comparable<Component.BaselineResizeBehavior>
, Constable
Component
public static enum Component.BaselineResizeBehavior extends Enum<Component.BaselineResizeBehavior>
Integer.MAX_VALUE
and/or Short.MAX_VALUE
the baseline may change in a way other than the baseline resize behavior indicates.Enum.EnumDesc<E extends Enum<E>>
Enum Constant | Description |
---|---|
CENTER_OFFSET |
Indicates the baseline remains a fixed distance from the center of the component. |
CONSTANT_ASCENT |
Indicates the baseline remains fixed relative to the y-origin. |
CONSTANT_DESCENT |
Indicates the baseline remains fixed relative to the height and does not change as the width is varied. |
OTHER |
Indicates the baseline resize behavior can not be expressed using any of the other constants. |
Modifier and Type | Method | Description |
---|---|---|
static Component.BaselineResizeBehavior |
valueOf |
Returns the enum constant of this class with the specified name. |
static Component.BaselineResizeBehavior[] |
values() |
Returns an array containing the constants of this enum class, in the order they are declared. |
public static final Component.BaselineResizeBehavior CONSTANT_ASCENT
getBaseline
returns the same value regardless of the height or width. For example, a JLabel
containing non-empty text with a vertical alignment of TOP
should have a baseline type of CONSTANT_ASCENT
.public static final Component.BaselineResizeBehavior CONSTANT_DESCENT
getBaseline(w, H)
is the same. For example, a JLabel
containing non-empty text with a vertical alignment of BOTTOM
should have a baseline type of CONSTANT_DESCENT
.public static final Component.BaselineResizeBehavior CENTER_OFFSET
getBaseline(w, H)
and H / 2
is the same (plus or minus one depending upon rounding error). Because of possible rounding errors it is recommended you ask for the baseline with two consecutive heights and use the return value to determine if you need to pad calculations by 1. The following shows how to calculate the baseline for any height:
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;
public static final Component.BaselineResizeBehavior OTHER
public static Component.BaselineResizeBehavior[] values()
public static Component.BaselineResizeBehavior valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
© 1993, 2023, 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/21/docs/api/java.desktop/java/awt/Component.BaselineResizeBehavior.html