Class JXLabel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JLabel
-
- org.jdesktop.swingx.JXLabel
-
- All Implemented Interfaces:
java.awt.image.ImageObserver,java.awt.MenuContainer,java.io.Serializable,javax.accessibility.Accessible,javax.swing.SwingConstants,BackgroundPaintable
- Direct Known Subclasses:
BasicHeaderUI.DescriptionPane
@JavaBean public class JXLabel extends javax.swing.JLabel implements BackgroundPaintable
A
JLabelsubclass which supportsPainters, multi-line text, and text rotation.Painter support consists of the
foregroundPainterandbackgroundPainterproperties. ThebackgroundPainterrefers to a painter responsible for painting beneath the text and icon. This painter, if set, will paint regardless of theopaqueproperty. If the background painter does not fully paint each pixel, then you should make sure theopaqueproperty is set to false.The
foregroundPainteris responsible for painting the icon and the text label. If no foregroundPainter is specified, then the look and feel will paint the label. Note that if opaque is set to true and the look and feel is rendering the foreground, then the foreground may paint over the background. Most look and feels will paint a background whenopaqueis true. To avoid this behavior, setopaqueto false.Since JXLabel is not opaque by default (
isOpaque()returns false), neither of these problems typically present themselves.Multi-line text is enabled via the
lineWrapproperty. Simply set it to true. By default, line wrapping occurs on word boundaries.The text (actually, the entire foreground and background) of the JXLabel may be rotated. Set the
rotationproperty to specify what the rotation should be. Specify rotation angle in radian units.- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classJXLabel.BasicDocumentprivate static classJXLabel.BasicViewFactoryprotected static interfaceJXLabel.IValuestatic classJXLabel.MultiLineSupport(package private) static classJXLabel.RendererRoot text view that acts as an renderer.static classJXLabel.TextAlignmentText alignment enums.-
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
-
-
Field Summary
Fields Modifier and Type Field Description private PainterbackgroundPainterprivate booleandontIgnoreRepaintprivate PainterforegroundPainterstatic doubleINVERTEDprivate intmaxLineSpanprivate booleanmultiLinestatic doubleNORMALprivate intoccupiedWidthprivate static java.lang.StringoldRendererKeyprivate booleanpaintBorderInsetsbooleanpaintedprivate booleanpaintingprivate intpHeightprivate intpWidthprivate JXLabel.TextAlignmenttextAlignmentprivate doubletextRotationstatic doubleVERTICAL_LEFTstatic doubleVERTICAL_RIGHT-
Fields inherited from class javax.swing.JComponent
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
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
-
-
Constructor Summary
Constructors Constructor Description JXLabel()Create a new JXLabel.JXLabel(java.lang.String text)Create a new JXLabel with the given text as the text for the label.JXLabel(java.lang.String text, int horizontalAlignment)Creates new JXLabel with given text and alignment.JXLabel(java.lang.String text, javax.swing.Icon image, int horizontalAlignment)Creates new JXLabel with given text, icon and alignment.JXLabel(javax.swing.Icon image)Creates new JXLabel with given icon.JXLabel(javax.swing.Icon image, int horizontalAlignment)Creates new JXLabel with given icon and alignment.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.awt.RectanglecalculateIconRect()private java.awt.geom.Point2DcalculateT()PaintergetBackgroundPainter()Returns the current background painter.PaintergetForegroundPainter()Returns the current foregroundPainter.intgetHeight()intgetMaxLineSpan()protected JXLabel.MultiLineSupportgetMultiLineSupport()protected intgetOccupiedWidth()java.awt.DimensiongetPreferredSize()JXLabel.TextAlignmentgetTextAlignment()Gets current text wrapping style.doublegetTextRotation()Gets current value of text rotation in rads.private java.awt.ContainergetViewport()intgetWidth()private javax.swing.text.ViewgetWrappingView()private voidinitLineWrapSupport()Helper method for initializing multi line support.private voidinitPainterSupport()booleanisLineWrap()Returns the current status of line wrap support.booleanisOpaque()booleanisPaintBorderInsets()Returns true if the background painter should paint where the border is or false if it should only paint inside the border.protected voidpaintComponent(java.awt.Graphics g)voidrepaint()voidrepaint(int x, int y, int width, int height)voidrepaint(long tm)voidrepaint(long tm, int x, int y, int width, int height)voidreshape(int x, int y, int w, int h)private static introtateHeight(java.awt.Dimension size, double theta)private static introtateWidth(java.awt.Dimension size, double theta)voidsetBackgroundPainter(Painter p)Sets a Painter to use to paint the background of this component By default there is already a single painter installed which draws the normal background for this component according to the current Look and Feel.voidsetForegroundPainter(Painter painter)Sets a new foregroundPainter on the label.voidsetLineWrap(boolean b)Enables line wrapping support for plain text.voidsetMaxLineSpan(int maxLineSpan)voidsetPaintBorderInsets(boolean paintBorderInsets)Sets the paintBorderInsets property.voidsetTextAlignment(JXLabel.TextAlignment alignment)Sets style of wrapping the text.voidsetTextRotation(double textOrientation)Sets new value for text rotation.-
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, updateUI
-
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, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
NORMAL
public static final double NORMAL
- See Also:
- Constant Field Values
-
INVERTED
public static final double INVERTED
- See Also:
- Constant Field Values
-
VERTICAL_LEFT
public static final double VERTICAL_LEFT
- See Also:
- Constant Field Values
-
VERTICAL_RIGHT
public static final double VERTICAL_RIGHT
- See Also:
- Constant Field Values
-
textRotation
private double textRotation
-
painting
private boolean painting
-
foregroundPainter
private Painter foregroundPainter
-
backgroundPainter
private Painter backgroundPainter
-
multiLine
private boolean multiLine
-
pWidth
private int pWidth
-
pHeight
private int pHeight
-
dontIgnoreRepaint
private boolean dontIgnoreRepaint
-
occupiedWidth
private int occupiedWidth
-
oldRendererKey
private static final java.lang.String oldRendererKey
- See Also:
- Constant Field Values
-
paintBorderInsets
private boolean paintBorderInsets
-
maxLineSpan
private int maxLineSpan
-
painted
public boolean painted
-
textAlignment
private JXLabel.TextAlignment textAlignment
-
-
Constructor Detail
-
JXLabel
public JXLabel()
Create a new JXLabel. This has the same semantics as creating a new JLabel.
-
JXLabel
public JXLabel(javax.swing.Icon image)
Creates new JXLabel with given icon.- Parameters:
image- the icon to set.
-
JXLabel
public JXLabel(javax.swing.Icon image, int horizontalAlignment)Creates new JXLabel with given icon and alignment.- Parameters:
image- the icon to set.horizontalAlignment- the text alignment.
-
JXLabel
public JXLabel(java.lang.String text)
Create a new JXLabel with the given text as the text for the label. This is shorthand for:JXLabel label = new JXLabel(); label.setText("Some Text");- Parameters:
text- the text to set.
-
JXLabel
public JXLabel(java.lang.String text, javax.swing.Icon image, int horizontalAlignment)Creates new JXLabel with given text, icon and alignment.- Parameters:
text- the test to set.image- the icon to set.horizontalAlignment- the text alignment relative to the icon.
-
JXLabel
public JXLabel(java.lang.String text, int horizontalAlignment)Creates new JXLabel with given text and alignment.- Parameters:
text- the test to set.horizontalAlignment- the text alignment.
-
-
Method Detail
-
initPainterSupport
private void initPainterSupport()
-
initLineWrapSupport
private void initLineWrapSupport()
Helper method for initializing multi line support.
-
getForegroundPainter
public final Painter getForegroundPainter()
Returns the current foregroundPainter. This is a bound property. By default the foregroundPainter will be an internal painter which executes the standard painting code (paintComponent()).- Returns:
- the current foreground painter.
-
reshape
public void reshape(int x, int y, int w, int h)- Overrides:
reshapein classjavax.swing.JComponent
-
setForegroundPainter
public void setForegroundPainter(Painter painter)
Sets a new foregroundPainter on the label. This will replace the existing foreground painter. Existing painters can be wrapped by using a CompoundPainter.- Parameters:
painter-
-
setBackgroundPainter
public void setBackgroundPainter(Painter p)
Sets a Painter to use to paint the background of this component By default there is already a single painter installed which draws the normal background for this component according to the current Look and Feel. CallingsetBackgroundPainterwill replace that existing painter.- Specified by:
setBackgroundPainterin interfaceBackgroundPaintable- Parameters:
p- the new painter- See Also:
getBackgroundPainter()
-
getBackgroundPainter
public final Painter getBackgroundPainter()
Returns the current background painter. The default value of this property is a painter which draws the normal JPanel background according to the current look and feel.- Specified by:
getBackgroundPainterin interfaceBackgroundPaintable- Returns:
- the current painter
- See Also:
setBackgroundPainter(Painter)
-
getTextRotation
public double getTextRotation()
Gets current value of text rotation in rads.- Returns:
- a double representing the current rotation of the text
- See Also:
setTextRotation(double)
-
getPreferredSize
public java.awt.Dimension getPreferredSize()
- Overrides:
getPreferredSizein classjavax.swing.JComponent
-
getWrappingView
private javax.swing.text.View getWrappingView()
-
getViewport
private java.awt.Container getViewport()
-
calculateIconRect
private java.awt.Rectangle calculateIconRect()
-
getMaxLineSpan
public int getMaxLineSpan()
-
setMaxLineSpan
public void setMaxLineSpan(int maxLineSpan)
-
rotateWidth
private static int rotateWidth(java.awt.Dimension size, double theta)
-
rotateHeight
private static int rotateHeight(java.awt.Dimension size, double theta)
-
setTextRotation
public void setTextRotation(double textOrientation)
Sets new value for text rotation. The value can be anything in range <0,2PI>. Note that although property name suggests only text rotation, the whole foreground painter is rotated in fact. Due to various reasons it is strongly discouraged to access any size related properties of the label from other threads then EDT when this property is set.- Parameters:
textOrientation- Value for text rotation in range <0,2PI>- See Also:
getTextRotation()
-
setLineWrap
public void setLineWrap(boolean b)
Enables line wrapping support for plain text. By default this support is disabled to mimic default of the JLabel. Value of this property has no effect on HTML text.- Parameters:
b- the new value
-
isLineWrap
public boolean isLineWrap()
Returns the current status of line wrap support. The default value of this property is false to mimic default JLabel behavior. Value of this property has no effect on HTML text.- Returns:
- the current multiple line splitting status
-
getTextAlignment
public JXLabel.TextAlignment getTextAlignment()
Gets current text wrapping style.- Returns:
- the text alignment for this label
-
setTextAlignment
public void setTextAlignment(JXLabel.TextAlignment alignment)
Sets style of wrapping the text.- Parameters:
alignment-- See Also:
for accepted values.
-
isPaintBorderInsets
public boolean isPaintBorderInsets()
Returns true if the background painter should paint where the border is or false if it should only paint inside the border. This property is true by default. This property affects the width, height, and initial transform passed to the background painter.- Specified by:
isPaintBorderInsetsin interfaceBackgroundPaintable- Returns:
- current value of the paintBorderInsets property
-
isOpaque
public boolean isOpaque()
- Overrides:
isOpaquein classjavax.swing.JComponent
-
setPaintBorderInsets
public void setPaintBorderInsets(boolean paintBorderInsets)
Sets the paintBorderInsets property. Set to true if the background painter should paint where the border is or false if it should only paint inside the border. This property is true by default. This property affects the width, height, and initial transform passed to the background painter. This is a bound property.- Specified by:
setPaintBorderInsetsin interfaceBackgroundPaintable- Parameters:
paintBorderInsets- new value of the paintBorderInsets property
-
paintComponent
protected void paintComponent(java.awt.Graphics g)
- Overrides:
paintComponentin classjavax.swing.JComponent- Parameters:
g- graphics to paint on
-
calculateT
private java.awt.geom.Point2D calculateT()
-
repaint
public void repaint()
- Overrides:
repaintin classjava.awt.Component
-
repaint
public void repaint(int x, int y, int width, int height)- Overrides:
repaintin classjava.awt.Component
-
repaint
public void repaint(long tm)
- Overrides:
repaintin classjava.awt.Component
-
repaint
public void repaint(long tm, int x, int y, int width, int height)- Overrides:
repaintin classjavax.swing.JComponent
-
getHeight
public int getHeight()
- Overrides:
getHeightin classjavax.swing.JComponent
-
getWidth
public int getWidth()
- Overrides:
getWidthin classjavax.swing.JComponent
-
getMultiLineSupport
protected JXLabel.MultiLineSupport getMultiLineSupport()
-
getOccupiedWidth
protected int getOccupiedWidth()
-
-