Top Description Constructors Methods
javax.swing.plaf

public abstract Class ComponentUI

extends Object
Class Inheritance
Known Direct Subclasses
javax.swing.plaf.DesktopIconUI, javax.swing.plaf.DesktopPaneUI, javax.swing.plaf.FileChooserUI, javax.swing.plaf.LabelUI, javax.swing.plaf.LayerUI, javax.swing.plaf.ListUI, javax.swing.plaf.MenuBarUI, javax.swing.plaf.OptionPaneUI, javax.swing.plaf.PanelUI, javax.swing.plaf.PopupMenuUI, javax.swing.plaf.ProgressBarUI, javax.swing.plaf.RootPaneUI, javax.swing.plaf.ScrollBarUI, javax.swing.plaf.ScrollPaneUI, javax.swing.plaf.SeparatorUI, javax.swing.plaf.SliderUI, javax.swing.plaf.SpinnerUI, javax.swing.plaf.SplitPaneUI, javax.swing.plaf.TabbedPaneUI, javax.swing.plaf.TableHeaderUI, javax.swing.plaf.TableUI, javax.swing.plaf.TextUI, javax.swing.plaf.ToolBarUI, javax.swing.plaf.ToolTipUI, javax.swing.plaf.TreeUI, javax.swing.plaf.ViewportUI, javax.swing.plaf.InternalFrameUI, javax.swing.plaf.ButtonUI, javax.swing.plaf.ColorChooserUI, javax.swing.plaf.ComboBoxUI
Imports
javax.swing.JComponent, .SwingUtilities, javax.accessibility.Accessible, java.awt.Component, .Container, .Dimension, .Graphics, .Insets

The base class for all UI delegate objects in the Swing pluggable look and feel architecture. The UI delegate object for a Swing component is responsible for implementing the aspects of the component that depend on the look and feel. The 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.
See Also
javax.swing.JComponent, javax.swing.UIManager

Constructor Summary

AccessConstructor and Description
public
ComponentUI()

Sole constructor.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the specified x,y location is contained within the look and feel's defined shape for the given component
contains
(JComponent
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
c
,
int
the x coordinate of the point
x
,
int
the y coordinate of the point
y
)

Returns true if the specified x,y location is contained within the look and feel's defined shape of the specified component.

public static ComponentUI

Returns:

a ComponentUI object for c
createUI
(JComponent
a JComponent for which to create a UI delegate
c
)

Returns an instance of the UI delegate for the specified component.

public Accessible

Returns:

the ith Accessible child of the object
getAccessibleChild
(JComponent
a JComponent for which to get a child object
c
,
int
zero-based index of child
i
)

Returns the ith Accessible child of the object.

public int

Returns:

the number of accessible children in the object
getAccessibleChildrenCount
(JComponent
JComponent for which to get count of accessible children
c
)

Returns the number of accessible children in the object.

public int

Returns:

baseline or a value < 0 indicating there is no reasonable baseline
getBaseline
(JComponent
JComponent baseline is being requested for
c
,
int
the width to get the baseline for
width
,
int
the height to get the baseline for
height
)

Returns the baseline.

public Component.BaselineResizeBehavior

Returns:

an enum indicating how the baseline changes as the component size changes
getBaselineResizeBehavior
(JComponent
JComponent to return baseline resize behavior for
c
)

Returns an enum indicating how the baseline of the component changes as the size changes.

public Dimension

Returns:

a Dimension object or null
getMaximumSize
(JComponent
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
c
)

Returns the specified component's maximum size appropriate for the look and feel.

public Dimension

Returns:

a Dimension object or null
getMinimumSize
(JComponent
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
c
)

Returns the specified component's minimum size appropriate for the look and feel.

public Dimension

Returns:

a Dimension object containing given component's preferred size appropriate for the look and feel
getPreferredSize
(JComponent
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
c
)

Returns the specified component's preferred size appropriate for the look and feel.

public void
installUI(JComponent
the component where this UI delegate is being installed
c
)

Configures the specified component appropriately for the look and feel.

public void
paint(Graphics
the Graphics context in which to paint
g
,
JComponent
the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
c
)

Paints the specified component appropriately for the look and feel.

public void
uninstallUI(JComponent
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
c
)

Reverses configuration which was done on the specified component during installUI.

public void
update(Graphics
the Graphics context in which to paint
g
,
JComponent
the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components
c
)

Notifies this UI delegate that it is time to paint the specified component.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ComponentUIback to summary
public ComponentUI()

Sole constructor. (For invocation by subclass constructors, typically implicit.)

Method Detail

containsback to summary
public boolean contains(JComponent c, int x, int y)

Returns 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.

Parameters
c:JComponent

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:int

the x coordinate of the point

y:int

the y coordinate of the point

Returns:boolean

true if the specified x,y location is contained within the look and feel's defined shape for the given component

Annotations
@SuppressWarnings:deprecation
See Also
javax.swing.JComponent#contains, java.awt.Component#contains
createUIback to summary
public static ComponentUI createUI(JComponent c)

Returns an instance of the UI delegate for the specified component. Each subclass must provide its own static 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.

Parameters
c:JComponent

a JComponent for which to create a UI delegate

Returns:ComponentUI

a ComponentUI object for c

getAccessibleChildback to summary
public Accessible getAccessibleChild(JComponent c, int i)

Returns the 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.

Parameters
c:JComponent

a JComponent for which to get a child object

i:int

zero-based index of child

Returns:Accessible

the ith Accessible child of the object

See Also
getAccessibleChildrenCount
getAccessibleChildrenCountback to summary
public int getAccessibleChildrenCount(JComponent c)

Returns the number of accessible children in the object. If all of the children of this object implement 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.

Parameters
c:JComponent

JComponent for which to get count of accessible children

Returns:int

the number of accessible children in the object

See Also
getAccessibleChild
getBaselineback to summary
public int getBaseline(JComponent c, int width, int height)

Returns the baseline. The baseline is measured from the top of the component. This method is primarily meant for 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.

Parameters
c:JComponent

JComponent baseline is being requested for

width:int

the width to get the baseline for

height:int

the height to get the baseline for

Returns:int

baseline or a value < 0 indicating there is no reasonable baseline

Exceptions
NullPointerException:
if c is null
IllegalArgumentException:
if width or height is < 0
Since
1.6
See Also
javax.swing.JComponent#getBaseline(int, int)
getBaselineResizeBehaviorback to summary
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)

Returns an enum indicating how the baseline of the component changes as the size changes. This method is primarily meant for layout managers and GUI builders.

This method returns BaselineResizeBehavior.OTHER. Subclasses that support a baseline should override appropriately.

Parameters
c:JComponent

JComponent to return baseline resize behavior for

Returns:Component.BaselineResizeBehavior

an enum indicating how the baseline changes as the component size changes

Exceptions
NullPointerException:
if c is null
Since
1.6
See Also
javax.swing.JComponent#getBaseline(int, int)
getMaximumSizeback to summary
public Dimension getMaximumSize(JComponent c)

Returns the specified component's maximum size appropriate for the look and feel. If 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.

Parameters
c:JComponent

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

Returns:Dimension

a Dimension object or null

See Also
javax.swing.JComponent#getMaximumSize, java.awt.LayoutManager2#maximumLayoutSize
getMinimumSizeback to summary
public Dimension getMinimumSize(JComponent c)

Returns the specified component's minimum size appropriate for the look and feel. If 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.

Parameters
c:JComponent

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

Returns:Dimension

a Dimension object or null

See Also
javax.swing.JComponent#getMinimumSize, java.awt.LayoutManager#minimumLayoutSize, getPreferredSize
getPreferredSizeback to summary
public Dimension getPreferredSize(JComponent c)

Returns the specified component's preferred size appropriate for the look and feel. If 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.

Parameters
c:JComponent

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

Returns:Dimension

a Dimension object containing given component's preferred size appropriate for the look and feel

See Also
javax.swing.JComponent#getPreferredSize, java.awt.LayoutManager#preferredLayoutSize
installUIback to summary
public void installUI(JComponent c)

Configures the specified component appropriately for the look and feel. This method is invoked when the 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:

  1. Install default property values for color, fonts, borders, icons, opacity, etc. on the component. Whenever possible, property values initialized by the client program should not be overridden.
  2. Install a LayoutManager on the component if necessary.
  3. Create/add any required sub-components to the component.
  4. Create/install event listeners on the component.
  5. Create/install a PropertyChangeListener on the component in order to detect and respond to component property changes appropriately.
  6. Install keyboard UI (mnemonics, traversal, etc.) on the component.
  7. Initialize any appropriate instance data.
Parameters
c:JComponent

the component where this UI delegate is being installed

See Also
uninstallUI, javax.swing.JComponent#setUI, javax.swing.JComponent#updateUI
paintback to summary
public void paint(Graphics g, JComponent c)

Paints the specified component appropriately for the look and feel. This method is invoked from the 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.

Parameters
g:Graphics

the Graphics context in which to paint

c:JComponent

the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

See Also
update
uninstallUIback to summary
public void uninstallUI(JComponent c)

Reverses configuration which was done on the specified component during 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:

  1. Remove any UI-set borders from the component.
  2. Remove any UI-set layout managers on the component.
  3. Remove any UI-added sub-components from the component.
  4. Remove any UI-added event/property listeners from the component.
  5. Remove any UI-installed keyboard UI from the component.
  6. Nullify any allocated instance data objects to allow for GC.
Parameters
c:JComponent

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

See Also
installUI, javax.swing.JComponent#updateUI
updateback to summary
public void update(Graphics g, JComponent c)

Notifies this UI delegate that it is time to paint the specified component. This method is invoked by 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.

Parameters
g:Graphics

the Graphics context in which to paint

c:JComponent

the component being painted; this argument is often ignored, but might be used if the UI object is stateless and shared by multiple components

See Also
paint, javax.swing.JComponent#paintComponent