public abstract class ComponentUI extends Object
JComponent class invokes methods from this class in order to delegate operations (painting, layout calculations, etc.) that may vary depending on the look and feel installed.
Client programs should not invoke methods on this class directly.
JComponent,
UIManager
| Constructor and Description |
|---|
ComponentUI()
Sole constructor.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
contains(JComponent
Returns
true if the specified
x,y location is contained within the look and feel's defined shape of the specified component.
|
static ComponentUI |
createUI(JComponent
Returns an instance of the UI delegate for the specified component.
|
Accessible |
getAccessibleChild(JComponent
Returns the
ith
Accessible child of the object.
|
int |
getAccessibleChildrenCount(JComponent
Returns the number of accessible children in the object.
|
int |
getBaseline(JComponent
Returns the baseline.
|
Component |
getBaselineResizeBehavior(JComponent
Returns an enum indicating how the baseline of he component changes as the size changes.
|
Dimension |
getMaximumSize(JComponent
Returns the specified component's maximum size appropriate for the look and feel.
|
Dimension |
getMinimumSize(JComponent
Returns the specified component's minimum size appropriate for the look and feel.
|
Dimension |
getPreferredSize(JComponent
Returns the specified component's preferred size appropriate for the look and feel.
|
void |
installUI(JComponent
Configures the specified component appropriately for the look and feel.
|
void |
paint(Graphics
Paints the specified component appropriately for the look and feel.
|
void |
uninstallUI(JComponent
Reverses configuration which was done on the specified component during
installUI.
|
void |
update(Graphics
Notifies this UI delegate that it is time to paint the specified component.
|
public ComponentUI()
public void installUI(JComponentc)
ComponentUI instance is being installed as the UI delegate on the specified component. This method should completely configure the component for the look and feel, including the following:
LayoutManager on the component if necessary. PropertyChangeListener on the component in order to detect and respond to component property changes appropriately. c - the component where this UI delegate is being installed
uninstallUI(javax.swing.JComponent),
JComponent.setUI(javax.swing.plaf.ComponentUI) ,
JComponent.updateUI()
public void uninstallUI(JComponentc)
installUI. This method is invoked when this
UIComponent instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed in
installUI, being careful to leave the
JComponent instance in a clean state (no extraneous listeners, look-and-feel-specific property objects, etc.). This should include the following:
c - the component from which this UI delegate is being removed; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
installUI(javax.swing.JComponent),
JComponent.updateUI()
public void paint(Graphicsg, JComponent c)
ComponentUI.update method when the specified component is being painted. Subclasses should override this method and use the specified
Graphics object to render the content of the component.
g - the
Graphics context in which to paint
c - the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
update(java.awt.Graphics, javax.swing.JComponent)
public void update(Graphicsg, JComponent c)
JComponent when the specified component is being painted.
By default this method fills the specified component with its background color if its opaque property is true, and then immediately calls paint. In general this method need not be overridden by subclasses; all look-and-feel rendering code should reside in the paint method.
g - the
Graphics context in which to paint
c - the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
paint(java.awt.Graphics, javax.swing.JComponent),
JComponent.paintComponent(java.awt.Graphics)
public DimensiongetPreferredSize(JComponent c)
null is returned, the preferred size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method returns
null.
c - the component whose preferred size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
JComponent.getPreferredSize() ,
LayoutManager.preferredLayoutSize(java.awt.Container)
public DimensiongetMinimumSize(JComponent c)
null is returned, the minimum size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method invokes
getPreferredSize and returns that value.
c - the component whose minimum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
Dimension object or
null
JComponent.getMinimumSize() ,
LayoutManager.minimumLayoutSize(java.awt.Container) ,
getPreferredSize(javax.swing.JComponent)
public DimensiongetMaximumSize(JComponent c)
null is returned, the maximum size will be calculated by the component's layout manager instead (this is the preferred approach for any component with a specific layout manager installed). The default implementation of this method invokes
getPreferredSize and returns that value.
c - the component whose maximum size is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
Dimension object or
null
JComponent.getMaximumSize() ,
LayoutManager2.maximumLayoutSize(java.awt.Container)
public boolean contains(JComponentc, int x, int y)
true if the specified
x,y location is contained within the look and feel's defined shape of the specified component.
x and
y are defined to be relative to the coordinate system of the specified component. Although a component's
bounds is constrained to a rectangle, this method provides the means for defining a non-rectangular shape within those bounds for the purpose of hit detection.
c - the component where the
x,y location is being queried; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
x - the
x coordinate of the point
y - the
y coordinate of the point
JComponent.contains(int, int) ,
Component.contains(int, int)
public static ComponentUIcreateUI(JComponent c)
createUI method that returns an instance of that UI delegate subclass. If the UI delegate subclass is stateless, it may return an instance that is shared by multiple components. If the UI delegate is stateful, then it should return a new instance per component. The default implementation of this method throws an error, as it should never be invoked.
public int getBaseline(JComponentc, int width, int height)
LayoutManagers to align components along their baseline. A return value less than 0 indicates this component does not have a reasonable baseline and that
LayoutManagers should not align this component on its baseline.
This method returns -1. Subclasses that have a meaningful baseline should override appropriately.
c -
JComponent baseline is being requested for
width - the width to get the baseline for
height - the height to get the baseline for
NullPointerException - if
c is
null
IllegalArgumentException - if width or height is < 0
JComponent.getBaseline(int,int)
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
This method returns BaselineResizeBehavior.OTHER. Subclasses that support a baseline should override appropriately.
c -
JComponent to return baseline resize behavior for
NullPointerException - if
c is
null
JComponent.getBaseline(int, int)
public int getAccessibleChildrenCount(JComponentc)
Accessible, this method should return the number of children of this object. UIs might wish to override this if they present areas on the screen that can be viewed as components, but actual components are not used for presenting those areas. Note: As of v1.3, it is recommended that developers call
Component.AccessibleAWTComponent.getAccessibleChildrenCount() instead of this method.
getAccessibleChild(javax.swing.JComponent, int)
public AccessiblegetAccessibleChild(JComponent c, int i)
ith
Accessible child of the object. UIs might need to override this if they present areas on the screen that can be viewed as components, but actual components are not used for presenting those areas.
Note: As of v1.3, it is recommended that developers call Component.AccessibleAWTComponent.getAccessibleChild() instead of this method.
i - zero-based index of child
ith
Accessible child of the object
getAccessibleChildrenCount(javax.swing.JComponent)