Enum Class Component.BaselineResizeBehavior
- All Implemented Interfaces:
Serializable, Comparable<Component.BaselineResizeBehavior>, Constable
- Enclosing class:
Component
Enumeration of the common ways the baseline of a component can
change as the size changes. The baseline resize behavior is
primarily for layout managers that need to know how the
position of the baseline changes as the component size changes.
In general the baseline resize behavior will be valid for sizes
greater than or equal to the minimum size (the actual minimum
size; not a developer specified minimum size). For sizes
smaller than the minimum size the baseline may change in a way
other than the baseline resize behavior indicates. Similarly,
as the size approaches
Integer.MAX_VALUE and/or
Short.MAX_VALUE the baseline may change in a way
other than the baseline resize behavior indicates.- Since:
- 1.6
- See Also:
-
Nested Class Summary
Nested classes/interfaces declared in class Enum
Enum.EnumDesc<E>Modifier and TypeClassDescriptionstatic final classEnum.EnumDesc<E extends Enum<E>>A nominal descriptor for anenumconstant. -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionIndicates the baseline remains a fixed distance from the center of the component.Indicates the baseline remains fixed relative to the y-origin.Indicates the baseline remains fixed relative to the height and does not change as the width is varied.Indicates the baseline resize behavior can not be expressed using any of the other constants. -
Method Summary
Modifier and TypeMethodDescriptionReturns 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.Methods declared in class Enum
clone, compareTo, describeConstable, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOfModifier and TypeMethodDescriptionprotected final Objectclone()Throws CloneNotSupportedException.final intCompares this enum with the specified object for order.Returns an enum descriptorEnumDescfor this instance, if one can be constructed, or an emptyOptionalif one cannot be.final booleanReturns true if the specified object is equal to this enum constant.protected final voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.Finalization has been deprecated for removal.Returns the Class object corresponding to this enum constant's enum type.final inthashCode()Returns a hash code for this enum constant.final Stringname()Returns the name of this enum constant, exactly as declared in its enum declaration.final intordinal()Returns the ordinal of this enumeration constant (its position in its enum declaration, where the initial constant is assigned an ordinal of zero).toString()Returns the name of this enum constant, as contained in the declaration.static <T extends Enum<T>>
TReturns the enum constant of the specified enum class with the specified name.Methods declared in class Object
getClass, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionfinal Class<?> getClass()Returns the runtime class of thisObject.final voidnotify()Wakes up a single thread that is waiting on this object's monitor.final voidWakes up all threads that are waiting on this object's monitor.final voidwait()Causes the current thread to wait until it is awakened, typically by being notified or interrupted.final voidwait(long timeoutMillis) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.final voidwait(long timeoutMillis, int nanos) Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
-
Enum Constant Details
-
CONSTANT_ASCENT
Indicates the baseline remains fixed relative to the y-origin. That is,getBaselinereturns the same value regardless of the height or width. For example, aJLabelcontaining non-empty text with a vertical alignment ofTOPshould have a baseline type ofCONSTANT_ASCENT. -
CONSTANT_DESCENT
Indicates the baseline remains fixed relative to the height and does not change as the width is varied. That is, for any height H the difference between H andgetBaseline(w, H)is the same. For example, aJLabelcontaining non-empty text with a vertical alignment ofBOTTOMshould have a baseline type ofCONSTANT_DESCENT. -
CENTER_OFFSET
Indicates the baseline remains a fixed distance from the center of the component. That is, for any height H the difference betweengetBaseline(w, H)andH / 2is 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; -
OTHER
Indicates the baseline resize behavior can not be expressed using any of the other constants. This may also indicate the baseline varies with the width of the component. This is also returned by components that do not have a baseline.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum class has no constant with the specified nameNullPointerException- if the argument is null
-