public class Baseline
extends java.lang.Object
getBaseline
uses the
following algorithm to determine the baseline:
getBaseline(JComponent,int,int)
method, invoke it.
UIManager
property of the name
Baseline.instance
, forward the call to that Baseline.
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.
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.
Modifier and Type | Field and Description |
---|---|
static int |
BRB_CENTER_OFFSET
Baseline resize behavior constant.
|
static int |
BRB_CONSTANT_ASCENT
Baseline resize behavior constant.
|
static int |
BRB_CONSTANT_DESCENT
Baseline resize behavior constant.
|
static int |
BRB_OTHER
Baseline resize behavior constant.
|
Modifier | Constructor and Description |
---|---|
protected |
Baseline()
Creates an instance of Baseline.
|
Modifier and Type | Method and Description |
---|---|
static int |
getBaseline(javax.swing.JComponent component)
Returns the baseline for the specified component, or -1 if the
baseline can not be determined.
|
static int |
getBaseline(javax.swing.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 |
getBaselineResizeBehavior(javax.swing.JComponent c)
Returns a constant indicating how the baseline varies with the size
of the component.
|
int |
getComponentBaseline(javax.swing.JComponent component,
int width,
int height)
Returns the baseline for the specified component, or -1 if the
baseline can not be determined.
|
public static final int BRB_CONSTANT_ASCENT
public static final int BRB_CONSTANT_DESCENT
public static final int BRB_CENTER_OFFSET
public static final int BRB_OTHER
protected Baseline()
A custom look and feel that wants to provide Baseline
support should put the instance in the defaults returned
from getDefaults
. 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.
public static int getBaselineResizeBehavior(javax.swing.JComponent c)
c
- the JComponent to get the baseline resize behavior forpublic static int getBaseline(javax.swing.JComponent component)
component
- JComponent to calculate baseline forpublic static int getBaseline(javax.swing.JComponent component, int width, int height)
component
- JComponent to calculate baseline forwidth
- Width of the component to determine baseline for.height
- Height of the component to determine baseline for.public int getComponentBaseline(javax.swing.JComponent component, int width, int height)
component
- JComponent to calculate baseline forwidth
- Width of the component to determine baseline for.height
- Height of the component to determine baseline for.