com.jgoodies.uif.component
Class UIFLabel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by com.jgoodies.uif.component.UIFLabel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, SwingConstants

public class UIFLabel
extends JLabel

In addition to the superclass JLabel, this class can render the label's text with anti-aliasing (AA) enabled. And it can use a custom font style and a custom font size. These attributes will be restored if the look&feel changes. Provides bound Java Bean properties fontStyle, fontSizeDelta and antiAliased.

If AA is enabled, it'll switch on the text anti-aliasing before painting the label. Subpixel AA is not used and not detected. And so, this label's AA mode will replace subpixel AA with plain AA, leading to a potentially decreased readability. Therefore the AA should be used only for larger font sizes where AA increases the readability, and the differences between AA and subpixel AA are minimal.

Version:
$Revision: 1.6 $
Author:
Karsten Lentzsch
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String PROPERTYNAME_ANTI_ALIASED
           
static String PROPERTYNAME_FONT_SIZE_DELTA
           
static String PROPERTYNAME_FONT_STYLE
           
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
UIFLabel(String text, boolean antiAliased)
          Constructs a UIFLabel for the given text, font style, font extra size, and anti-aliasing mode.
UIFLabel(String text, int fontStyle, int fontSizeDelta, boolean antiAliased)
          Constructs a UIFLabel for the given text, font style, font size delta, and anti-aliasing mode.
 
Method Summary
 int getFontSizeDelta()
          Returns the delta of this label's text font relative to the default font.
 int getFontStyle()
          Returns this label's font style.
 boolean isAntiAliased()
          Returns whether this label's text will be rendered with anti-aliasing enabled.
 void paint(Graphics g)
          Paints the label: switches on anti-aliasing if necessary.
 void setAntiAliased(boolean antiAliased)
          Enables or disabled the anti-aliasing of this label's text.
 void setFontSizeDelta(int newFontSizeDelta)
          Sets a new font size delta that will make this label's text larger or smaller than the default font.
 void setFontStyle(int newFontStyle)
          Sets a new font style that will be used to render this label's text.
 void updateUI()
          Restores the fonts after the UI has changed.
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTYNAME_FONT_STYLE

public static final String PROPERTYNAME_FONT_STYLE
See Also:
Constant Field Values

PROPERTYNAME_FONT_SIZE_DELTA

public static final String PROPERTYNAME_FONT_SIZE_DELTA
See Also:
Constant Field Values

PROPERTYNAME_ANTI_ALIASED

public static final String PROPERTYNAME_ANTI_ALIASED
See Also:
Constant Field Values
Constructor Detail

UIFLabel

public UIFLabel(String text,
                boolean antiAliased)
Constructs a UIFLabel for the given text, font style, font extra size, and anti-aliasing mode.

Parameters:
text - the initial text
antiAliased - true enables anti alias, false disables it

UIFLabel

public UIFLabel(String text,
                int fontStyle,
                int fontSizeDelta,
                boolean antiAliased)
Constructs a UIFLabel for the given text, font style, font size delta, and anti-aliasing mode.

Parameters:
text - the initial text
fontStyle - the style of the font to use: plain, bold, etc.
fontSizeDelta - a delta in pixel relative to the default font size
antiAliased - true enables anti alias, false disables it
Method Detail

getFontStyle

public int getFontStyle()
Returns this label's font style. Useful to force a bold text style.

Returns:
this label's font style
See Also:
Font

setFontStyle

public void setFontStyle(int newFontStyle)
Sets a new font style that will be used to render this label's text.

Parameters:
newFontStyle - the font style to set

getFontSizeDelta

public int getFontSizeDelta()
Returns the delta of this label's text font relative to the default font.

Returns:
the delta between the default font size and this label's font size

setFontSizeDelta

public void setFontSizeDelta(int newFontSizeDelta)
Sets a new font size delta that will make this label's text larger or smaller than the default font.

Parameters:
newFontSizeDelta - the font size delta to set

isAntiAliased

public boolean isAntiAliased()
Returns whether this label's text will be rendered with anti-aliasing enabled.

Returns:
true if anti-aliasing is enabled, false if disabled

setAntiAliased

public void setAntiAliased(boolean antiAliased)
Enables or disabled the anti-aliasing of this label's text.

Parameters:
antiAliased - true to enable anti-aliasing, false to disable it

paint

public void paint(Graphics g)
Paints the label: switches on anti-aliasing if necessary.

Overrides:
paint in class JComponent
Parameters:
g - the Graphics object to render on

updateUI

public void updateUI()
Restores the fonts after the UI has changed.

Overrides:
updateUI in class JLabel


Copyright © 2000-2008 JGoodies Karsten Lentzsch. All Rights Reserved.