Class ComponentUI
- Direct Known Subclasses:
-
ButtonUI
,ColorChooserUI
,ComboBoxUI
,DesktopIconUI
,DesktopPaneUI
,FileChooserUI
,InternalFrameUI
,LabelUI
,LayerUI
,ListUI
,MenuBarUI
,OptionPaneUI
,PanelUI
,PopupMenuUI
,ProgressBarUI
,RootPaneUI
,ScrollBarUI
,ScrollPaneUI
,SeparatorUI
,SliderUI
,SpinnerUI
,SplitPaneUI
,TabbedPaneUI
,TableHeaderUI
,TableUI
,TextUI
,ToolBarUI
,ToolTipUI
,TreeUI
,ViewportUI
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.
- See Also:
Constructor Summary
Constructor | Description |
---|---|
ComponentUI() |
Sole constructor. |
Method Summary
Modifier and Type | Method | Description |
---|---|---|
boolean |
contains |
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 |
Returns an instance of the UI delegate for the specified component. |
Accessible |
getAccessibleChild |
Returns the i th Accessible child of the object. |
int |
getAccessibleChildrenCount |
Returns the number of accessible children in the object. |
int |
getBaseline |
Returns the baseline. |
Component.BaselineResizeBehavior |
getBaselineResizeBehavior |
Returns an enum indicating how the baseline of the component changes as the size changes. |
Dimension |
getMaximumSize |
Returns the specified component's maximum size appropriate for the look and feel. |
Dimension |
getMinimumSize |
Returns the specified component's minimum size appropriate for the look and feel. |
Dimension |
getPreferredSize |
Returns the specified component's preferred size appropriate for the look and feel. |
void |
installUI |
Configures the specified component appropriately for the look and feel. |
void |
paint |
Paints the specified component appropriately for the look and feel. |
void |
uninstallUI |
Reverses configuration which was done on the specified component during installUI . |
void |
update |
Notifies this UI delegate that it is time to paint the specified component. |
Constructor Details
ComponentUI
public ComponentUI()
Method Details
installUI
public void installUI(JComponent c)
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: - 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.
- Install a
LayoutManager
on the component if necessary. - Create/add any required sub-components to the component.
- Create/install event listeners on the component.
- Create/install a
PropertyChangeListener
on the component in order to detect and respond to component property changes appropriately. - Install keyboard UI (mnemonics, traversal, etc.) on the component.
- Initialize any appropriate instance data.
- Parameters:
-
c
- the component where this UI delegate is being installed - See Also:
uninstallUI
public void uninstallUI(JComponent c)
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: - Remove any UI-set borders from the component.
- Remove any UI-set layout managers on the component.
- Remove any UI-added sub-components from the component.
- Remove any UI-added event/property listeners from the component.
- Remove any UI-installed keyboard UI from the component.
- Nullify any allocated instance data objects to allow for GC.
- Parameters:
-
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 - See Also:
paint
public void paint(Graphics g, 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.- Parameters:
-
g
- theGraphics
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 - See Also:
update
public void update(Graphics g, 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.
- Parameters:
-
g
- theGraphics
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 - See Also:
getPreferredSize
public Dimension getPreferredSize(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
.- Parameters:
-
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 - Returns:
- a
Dimension
object containing given component's preferred size appropriate for the look and feel - See Also:
getMinimumSize
public Dimension getMinimumSize(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.- Parameters:
-
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 - Returns:
- a
Dimension
object ornull
- See Also:
getMaximumSize
public Dimension getMaximumSize(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.- Parameters:
-
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 - Returns:
- a
Dimension
object ornull
- See Also:
contains
public boolean contains(JComponent c, 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.- Parameters:
-
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 - Returns:
-
true
if the specifiedx,y
location is contained within the look and feel's defined shape for the given component - See Also:
createUI
public static ComponentUI createUI(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.- Parameters:
-
c
- aJComponent
for which to create a UI delegate - Returns:
- a
ComponentUI
object forc
getBaseline
public int getBaseline(JComponent c, int width, int height)
LayoutManager
s to align components along their baseline. A return value less than 0 indicates this component does not have a reasonable baseline and that LayoutManager
s should not align this component on its baseline. This method returns -1. Subclasses that have a meaningful baseline should override appropriately.
- Parameters:
-
c
-JComponent
baseline is being requested for -
width
- the width to get the baseline for -
height
- the height to get the baseline for - Returns:
- baseline or a value < 0 indicating there is no reasonable baseline
- Throws:
-
NullPointerException
- ifc
isnull
-
IllegalArgumentException
- if width or height is < 0 - Since:
- 1.6
- See Also:
getBaselineResizeBehavior
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
This method returns BaselineResizeBehavior.OTHER
. Subclasses that support a baseline should override appropriately.
- Parameters:
-
c
-JComponent
to return baseline resize behavior for - Returns:
- an enum indicating how the baseline changes as the component size changes
- Throws:
-
NullPointerException
- ifc
isnull
- Since:
- 1.6
- See Also:
getAccessibleChildrenCount
public int getAccessibleChildrenCount(JComponent c)
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
for which to get count of accessible children - Returns:
- the number of accessible children in the object
- See Also:
getAccessibleChild
public Accessible getAccessibleChild(JComponent c, int i)
i
th 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
- aJComponent
for which to get a child object -
i
- zero-based index of child - Returns:
- the
i
thAccessible
child of the object - See Also:
© 1993, 2021, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/17/docs/api/java.desktop/javax/swing/plaf/ComponentUI.html