Class Baseline
getBaseline
uses the
following algorithm to determine the baseline:
- If the component has a
getBaseline(JComponent,int,int)
method, invoke it. - If there is a
UIManager
property of the nameBaseline.instance
, forward the call to that Baseline. - Otherwise use the built in support.
In addition to determining the baseline, this class also allows for determining how the baseline changes as the size of the component changes. The method getBaselineResizeBehavior can be used for this. This will return one of BRB_OTHER, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT or BRB_CENTER_OFFSET. The following algorithm is used in determining the baseline resize behavior.
- If the Component defines the method getBaselineResizeBehaviorInt, the return value from that method is used.
- If running on 1.6, the Component method getBaselineResizeBehavior is invoked and the return value converted to one of the constants defined by this class.
- If the component is one of the known Swing components,the baseline resize behavior is calculated and returned.
- Otherwise, BRB_OTHER is returned.
This class is primarily useful for JREs prior to 1.6. In 1.6 API for this was added directly to Component. When run on 1.6 or newer, this class calls into the appropriate Component methods.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
Baseline resize behavior constant.static final int
Baseline resize behavior constant.static final int
Baseline resize behavior constant.static final int
Baseline resize behavior constant. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
getBaseline
(JComponent component) Returns the baseline for the specified component, or -1 if the baseline can not be determined.static int
getBaseline
(JComponent component, int width, int height) Returns the baseline for the specified component, or a value less than 0 if the baseline can not be determined.static int
Returns a constant indicating how the baseline varies with the size of the component.int
getComponentBaseline
(JComponent component, int width, int height) Returns the baseline for the specified component, or -1 if the baseline can not be determined.
-
Field Details
-
BRB_CONSTANT_ASCENT
public static final int BRB_CONSTANT_ASCENTBaseline resize behavior constant. Indicates as the size of the component changes the baseline remains a fixed distance from the top of the component.- See Also:
-
BRB_CONSTANT_DESCENT
public static final int BRB_CONSTANT_DESCENTBaseline resize behavior constant. Indicates as the size of the component changes the baseline remains a fixed distance from the bottom of the component.- See Also:
-
BRB_CENTER_OFFSET
public static final int BRB_CENTER_OFFSETBaseline resize behavior constant. Indicates as the size of the component changes the baseline remains a fixed distance from the center of the component.- See Also:
-
BRB_OTHER
public static final int BRB_OTHERBaseline resize behavior constant. Indicates as the size of the component changes the baseline can not be determined using one of the other constants.- See Also:
-
-
Constructor Details
-
Baseline
protected Baseline()Creates an instance of Baseline. You typically don't create a Baseline. The constructor is provided by look and feels that wish to provide baseline support.A custom look and feel that wants to provide
Baseline
support should put the instance in the defaults returned fromgetDefaults
. If you want to override the baseline suport for a look and feel place the instance in the defaults returned from UIManager.getLookAndFeelDefaults(). Tthis will ensure that if the look and feel changes the appropriate baseline can be used.
-
-
Method Details
-
getBaselineResizeBehavior
Returns a constant indicating how the baseline varies with the size of the component.- Parameters:
c
- the JComponent to get the baseline resize behavior for- Returns:
- one of BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_CENTER_OFFSET or BRB_OTHER
-
getBaseline
Returns the baseline for the specified component, or -1 if the baseline can not be determined. The baseline is measured from the top of the component. This method returns the baseline based on the preferred size.- Parameters:
component
- JComponent to calculate baseline for- Returns:
- baseline for the specified component
-
getBaseline
Returns the baseline for the specified component, or a value less than 0 if the baseline can not be determined. The baseline is measured from the top of the component.- Parameters:
component
- JComponent to calculate baseline forwidth
- Width of the component to determine baseline for.height
- Height of the component to determine baseline for.- Returns:
- baseline for the specified component
-
getComponentBaseline
Returns the baseline for the specified component, or -1 if the baseline can not be determined. The baseline is measured from the top of the component.- Parameters:
component
- JComponent to calculate baseline forwidth
- Width of the component to determine baseline for.height
- Height of the component to determine baseline for.- Returns:
- baseline for the specified component
-