APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javax.swing.plaf.basic

public Class BasicLabelUI

extends LabelUI
implements PropertyChangeListener
Class Inheritance
All Implemented Interfaces
java.beans.PropertyChangeListener, java.util.EventListener
Known Direct Subclasses
javax.swing.plaf.metal.MetalLabelUI, javax.swing.plaf.synth.SynthLabelUI, com.sun.java.swing.plaf.motif.MotifLabelUI
Imports
sun.swing.SwingUtilities2, .DefaultLookup, .UIAction, javax.swing.*, javax.swing.plaf.*, javax.swing.text.View, java.awt.event.ActionEvent, .ActionListener, .InputEvent, .KeyEvent, java.awt.Component, .Container, .Dimension, .Rectangle, .Insets, .Color, .Graphics, .Font, .FontMetrics, java.beans.PropertyChangeEvent, .PropertyChangeListener

A Windows L&F implementation of LabelUI. This implementation is completely static, i.e. there's only one UIView implementation that's shared by all JLabel objects.
Author
Hans Muller

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
protected static BasicLabelUI
labelUI

The default BasicLabelUI instance.

private Rectangle
private Rectangle

Constructor Summary

AccessConstructor and Description
public
BasicLabelUI()

Constructs a BasicLabelUI.

Method Summary

Modifier and TypeMethod and Description
public static ComponentUI

Returns:

an instance of BasicLabelUI
createUI
(JComponent
a component
c
)

Hides javax.swing.plaf.ComponentUI.createUI.

Returns an instance of BasicLabelUI.

public int
getBaseline(JComponent c, int width, int height)

Overrides javax.swing.plaf.ComponentUI.getBaseline.

Returns the baseline.

public Component.BaselineResizeBehavior
getBaselineResizeBehavior(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getBaselineResizeBehavior.

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

public Dimension

Returns:

getPreferredSize(c)
getMaximumSize
(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMaximumSize.

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

public Dimension

Returns:

getPreferredSize(c)
getMinimumSize
(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMinimumSize.

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

public Dimension
getPreferredSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getPreferredSize.

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

protected void
installComponents(JLabel
an instance of JLabel
c
)

Registers components.

protected void
installDefaults(JLabel
an instance of JLabel
c
)

Installs default properties.

protected void
installKeyboardActions(JLabel
an instance of JLabel
l
)

Registers keyboard actions.

protected void
installListeners(JLabel
an instance of JLabel
c
)

Registers listeners.

public void
installUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.installUI.

Configures the specified component appropriately for the look and feel.

private String
layout(JLabel label, FontMetrics fm, int width, int height)

protected String

Returns:

a possibly clipped version of the compound labels string
layoutCL
(JLabel
an instance of JLabel
label
,
FontMetrics
a font metrics
fontMetrics
,
String
a text
text
,
Icon
an icon
icon
,
Rectangle
a bounding rectangle to lay out label
viewR
,
Rectangle
a bounding rectangle to lay out icon
iconR
,
Rectangle
a bounding rectangle to lay out text
textR
)

Forwards the call to SwingUtilities.layoutCompoundLabel().

pack-priv static void
public void
paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.paint.

Paints the label text with the foreground color, if the label is opaque then paints the entire background with the background color.

protected void
paintDisabledText(JLabel
an instance of JLabel
l
,
Graphics
an instance of Graphics
g
,
String
a text
s
,
int
an X coordinate
textX
,
int
an Y coordinate
textY
)

Paint clippedText at textX, textY with background.lighter() and then shifted down and to the right by one pixel with background.darker().

protected void
paintEnabledText(JLabel
an instance of JLabel
l
,
Graphics
an instance of Graphics
g
,
String
a text
s
,
int
an X coordinate
textX
,
int
an Y coordinate
textY
)

Paint clippedText at textX, textY with the labels foreground color.

public void
propertyChange(PropertyChangeEvent e)

Implements java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

protected void
uninstallComponents(JLabel
an instance of JLabel
c
)

Unregisters components.

protected void
uninstallDefaults(JLabel
an instance of JLabel
c
)

Uninstalls default properties.

protected void
uninstallKeyboardActions(JLabel
an instance of JLabel
c
)

Unregisters keyboard actions.

protected void
uninstallListeners(JLabel
an instance of JLabel
c
)

Unregisters listeners.

public void
uninstallUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.uninstallUI.

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

Field Detail

labelUIback to summary
protected static BasicLabelUI labelUI

The default BasicLabelUI instance. This field might not be used. To change the default instance use a subclass which overrides the createUI method, and place that class name in defaults table under the key "LabelUI".

paintIconRback to summary
private Rectangle paintIconR
paintTextRback to summary
private Rectangle paintTextR

Constructor Detail

BasicLabelUIback to summary
public BasicLabelUI()

Constructs a BasicLabelUI.

Method Detail

createUIback to summary
public static ComponentUI createUI(JComponent c)

Hides javax.swing.plaf.ComponentUI.createUI.

Returns an instance of BasicLabelUI.

Parameters
c:JComponent

a component

Returns:ComponentUI

an instance of BasicLabelUI

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

Overrides javax.swing.plaf.ComponentUI.getBaseline.

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

Overrides javax.swing.plaf.ComponentUI.getBaselineResizeBehavior.

Returns an enum indicating how the baseline of the component changes as the 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)

Overrides javax.swing.plaf.ComponentUI.getMaximumSize.

Doc from javax.swing.plaf.ComponentUI.getMaximumSize.

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.

Returns:Dimension

getPreferredSize(c)

getMinimumSizeback to summary
public Dimension getMinimumSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getMinimumSize.

Doc from javax.swing.plaf.ComponentUI.getMinimumSize.

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.

Returns:Dimension

getPreferredSize(c)

getPreferredSizeback to summary
public Dimension getPreferredSize(JComponent c)

Overrides javax.swing.plaf.ComponentUI.getPreferredSize.

Doc from javax.swing.plaf.ComponentUI.getPreferredSize.

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.

installComponentsback to summary
protected void installComponents(JLabel c)

Registers components.

Parameters
c:JLabel

an instance of JLabel

installDefaultsback to summary
protected void installDefaults(JLabel c)

Installs default properties.

Parameters
c:JLabel

an instance of JLabel

installKeyboardActionsback to summary
protected void installKeyboardActions(JLabel l)

Registers keyboard actions.

Parameters
l:JLabel

an instance of JLabel

installListenersback to summary
protected void installListeners(JLabel c)

Registers listeners.

Parameters
c:JLabel

an instance of JLabel

installUIback to summary
public void installUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.installUI.

Doc from javax.swing.plaf.ComponentUI.installUI.

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.
layoutback to summary
private String layout(JLabel label, FontMetrics fm, int width, int height)
layoutCLback to summary
protected String layoutCL(JLabel label, FontMetrics fontMetrics, String text, Icon icon, Rectangle viewR, Rectangle iconR, Rectangle textR)

Forwards the call to SwingUtilities.layoutCompoundLabel(). This method is here so that a subclass could do Label specific layout and to shorten the method name a little.

Parameters
label:JLabel

an instance of JLabel

fontMetrics:FontMetrics

a font metrics

text:String

a text

icon:Icon

an icon

viewR:Rectangle

a bounding rectangle to lay out label

iconR:Rectangle

a bounding rectangle to lay out icon

textR:Rectangle

a bounding rectangle to lay out text

Returns:String

a possibly clipped version of the compound labels string

See Also
SwingUtilities#layoutCompoundLabel
loadActionMapback to summary
pack-priv static void loadActionMap(LazyActionMap map)
paintback to summary
public void paint(Graphics g, JComponent c)

Overrides javax.swing.plaf.ComponentUI.paint.

Paints the label text with the foreground color, if the label is opaque then paints the entire background with the background color. The Label text is drawn by paintEnabledText or paintDisabledText. The locations of the label parts are computed by layoutCL.

See Also
paintEnabledText, paintDisabledText, layoutCL
paintDisabledTextback to summary
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX, int textY)

Paint clippedText at textX, textY with background.lighter() and then shifted down and to the right by one pixel with background.darker().

Parameters
l:JLabel

an instance of JLabel

g:Graphics

an instance of Graphics

s:String

a text

textX:int

an X coordinate

textY:int

an Y coordinate

See Also
paint, paintEnabledText
paintEnabledTextback to summary
protected void paintEnabledText(JLabel l, Graphics g, String s, int textX, int textY)

Paint clippedText at textX, textY with the labels foreground color.

Parameters
l:JLabel

an instance of JLabel

g:Graphics

an instance of Graphics

s:String

a text

textX:int

an X coordinate

textY:int

an Y coordinate

See Also
paint, paintDisabledText
propertyChangeback to summary
public void propertyChange(PropertyChangeEvent e)

Implements java.beans.PropertyChangeListener.propertyChange.

Doc from java.beans.PropertyChangeListener.propertyChange.

This method gets called when a bound property is changed.

uninstallComponentsback to summary
protected void uninstallComponents(JLabel c)

Unregisters components.

Parameters
c:JLabel

an instance of JLabel

uninstallDefaultsback to summary
protected void uninstallDefaults(JLabel c)

Uninstalls default properties.

Parameters
c:JLabel

an instance of JLabel

uninstallKeyboardActionsback to summary
protected void uninstallKeyboardActions(JLabel c)

Unregisters keyboard actions.

Parameters
c:JLabel

an instance of JLabel

uninstallListenersback to summary
protected void uninstallListeners(JLabel c)

Unregisters listeners.

Parameters
c:JLabel

an instance of JLabel

uninstallUIback to summary
public void uninstallUI(JComponent c)

Overrides javax.swing.plaf.ComponentUI.uninstallUI.

Doc from javax.swing.plaf.ComponentUI.uninstallUI.

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.
javax.swing.plaf.basic back to summary

private Class BasicLabelUI.Actions

extends UIAction
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final String
private static final String

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

private void
doPress(JLabel label)

private void
doRelease(JLabel label, boolean isCommand)

private void
putOnRelease(InputMap inputMap, int keyCode, int modifiers)

private void
removeOnRelease(InputMap inputMap, int keyCode, int modifiers)

Inherited from sun.swing.UIAction:
acceptaddPropertyChangeListenergetNamegetValueisEnabledputValueremovePropertyChangeListenersetEnabled

Field Detail

PRESSback to summary
private static final String PRESS
RELEASEback to summary
private static final String RELEASE

Constructor Detail

Actionsback to summary
pack-priv Actions(String key)

Method Detail

actionPerformedback to summary
public void actionPerformed(ActionEvent e)

Implements java.awt.event.ActionListener.actionPerformed.

Doc from java.awt.event.ActionListener.actionPerformed.

Invoked when an action occurs.

doPressback to summary
private void doPress(JLabel label)
doReleaseback to summary
private void doRelease(JLabel label, boolean isCommand)
putOnReleaseback to summary
private void putOnRelease(InputMap inputMap, int keyCode, int modifiers)
removeOnReleaseback to summary
private void removeOnRelease(InputMap inputMap, int keyCode, int modifiers)