- java.lang.Object
-
- javax.swing.plaf.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
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. TheJComponent
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:
JComponent
,UIManager
-
-
Constructor Summary
Constructors Constructor and Description ComponentUI()
Sole constructor.
-
Method Summary
Methods Modifier and Type Method and Description boolean
contains(JComponent c, int x, int y)
Returnstrue
if the specified x,y location is contained within the look and feel's defined shape of the specified component.static ComponentUI
createUI(JComponent c)
Returns an instance of the UI delegate for the specified component.Accessible
getAccessibleChild(JComponent c, int i)
Returns thei
thAccessible
child of the object.int
getAccessibleChildrenCount(JComponent c)
Returns the number of accessible children in the object.int
getBaseline(JComponent c, int width, int height)
Returns the baseline.Component.BaselineResizeBehavior
getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of he component changes as the size changes.Dimension
getMaximumSize(JComponent c)
Returns the specified component's maximum size appropriate for the look and feel.Dimension
getMinimumSize(JComponent c)
Returns the specified component's minimum size appropriate for the look and feel.Dimension
getPreferredSize(JComponent c)
Returns the specified component's preferred size appropriate for the look and feel.void
installUI(JComponent c)
Configures the specified component appropriately for the look and feel.void
paint(Graphics g, JComponent c)
Paints the specified component appropriately for the look and feel.void
uninstallUI(JComponent c)
Reverses configuration which was done on the specified component duringinstallUI
.void
update(Graphics g, JComponent c)
Notifies this UI delegate that it is time to paint the specified component.
-
-
-
Constructor Detail
-
ComponentUI
public ComponentUI()
Sole constructor. (For invocation by subclass constructors, typically implicit.)
-
-
Method Detail
-
installUI
public void installUI(JComponent c)
Configures the specified component appropriately for the look and feel. This method is invoked when theComponentUI
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(javax.swing.JComponent)
,JComponent.setUI(javax.swing.plaf.ComponentUI)
,JComponent.updateUI()
-
uninstallUI
public void uninstallUI(JComponent c)
Reverses configuration which was done on the specified component duringinstallUI
. This method is invoked when thisUIComponent
instance is being removed as the UI delegate for the specified component. This method should undo the configuration performed ininstallUI
, being careful to leave theJComponent
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:
installUI(javax.swing.JComponent)
,JComponent.updateUI()
-
paint
public void paint(Graphics g, JComponent c)
Paints the specified component appropriately for the look and feel. This method is invoked from theComponentUI.update
method when the specified component is being painted. Subclasses should override this method and use the specifiedGraphics
object to render the content of the component.- Parameters:
g
- theGraphics
context in which to paintc
- 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(java.awt.Graphics, javax.swing.JComponent)
-
update
public void update(Graphics g, JComponent c)
Notifies this UI delegate that it is time to paint the specified component. This method is invoked byJComponent
when the specified component is being painted.By default this method fills the specified component with its background color if its
opaque
property istrue
, and then immediately callspaint
. In general this method need not be overridden by subclasses; all look-and-feel rendering code should reside in thepaint
method.- Parameters:
g
- theGraphics
context in which to paintc
- 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(java.awt.Graphics, javax.swing.JComponent)
,JComponent.paintComponent(java.awt.Graphics)
-
getPreferredSize
public Dimension getPreferredSize(JComponent c)
Returns the specified component's preferred size appropriate for the look and feel. Ifnull
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 returnsnull
.- 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- See Also:
JComponent.getPreferredSize()
,LayoutManager.preferredLayoutSize(java.awt.Container)
-
getMinimumSize
public Dimension getMinimumSize(JComponent c)
Returns the specified component's minimum size appropriate for the look and feel. Ifnull
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 invokesgetPreferredSize
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:
JComponent.getMinimumSize()
,LayoutManager.minimumLayoutSize(java.awt.Container)
,getPreferredSize(javax.swing.JComponent)
-
getMaximumSize
public Dimension getMaximumSize(JComponent c)
Returns the specified component's maximum size appropriate for the look and feel. Ifnull
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 invokesgetPreferredSize
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:
JComponent.getMaximumSize()
,LayoutManager2.maximumLayoutSize(java.awt.Container)
-
contains
public boolean contains(JComponent c, int x, int y)
Returnstrue
if the specified x,y location is contained within the look and feel's defined shape of the specified component.x
andy
are defined to be relative to the coordinate system of the specified component. Although a component'sbounds
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 componentsx
- the x coordinate of the pointy
- the y coordinate of the point- See Also:
JComponent.contains(int, int)
,Component.contains(int, int)
-
createUI
public static ComponentUI createUI(JComponent c)
Returns an instance of the UI delegate for the specified component. Each subclass must provide its own staticcreateUI
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.
-
getBaseline
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 forLayoutManager
s to align components along their baseline. A return value less than 0 indicates this component does not have a reasonable baseline and thatLayoutManager
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 forwidth
- the width to get the baseline forheight
- 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:
JComponent.getBaseline(int,int)
-
getBaselineResizeBehavior
public Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of he 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
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:
JComponent.getBaseline(int, int)
-
getAccessibleChildrenCount
public int getAccessibleChildrenCount(JComponent c)
Returns the number of accessible children in the object. If all of the children of this object implementAccessible
, 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 callComponent.AccessibleAWTComponent.getAccessibleChildrenCount()
instead of this method.- Returns:
- the number of accessible children in the object
- See Also:
getAccessibleChild(javax.swing.JComponent, int)
-
getAccessibleChild
public Accessible getAccessibleChild(JComponent c, int i)
Returns thei
thAccessible
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:
i
- zero-based index of child- Returns:
- the
i
thAccessible
child of the object - See Also:
getAccessibleChildrenCount(javax.swing.JComponent)
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/12/2024 09:41:17 Cette version de la page est en cache (à la date du 22/12/2024 09:41:17) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 30/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/plaf/ComponentUI.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.