public class JXLabel extends JLabel implements BackgroundPaintable
A JLabel
subclass which supports Painter
s, multi-line text,
and text rotation.
Painter support consists of the foregroundPainter
and backgroundPainter
properties. The
backgroundPainter
refers to a painter responsible for painting beneath the text and icon. This
painter, if set, will paint regardless of the opaque
property. If the background painter does not
fully paint each pixel, then you should make sure the opaque
property is set to false.
The foregroundPainter
is 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 when opaque
is true. To avoid this behavior, set opaque
to 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 lineWrap
property. 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
rotation
property to specify what the rotation should be. Specify rotation angle in radian units.
Modifier and Type | Class and Description |
---|---|
(package private) static class |
JXLabel.BasicDocument |
private static class |
JXLabel.BasicViewFactory |
protected static interface |
JXLabel.IValue |
static class |
JXLabel.MultiLineSupport |
(package private) static class |
JXLabel.Renderer
Root text view that acts as an renderer.
|
static class |
JXLabel.TextAlignment
Text alignment enums.
|
JLabel.AccessibleJLabel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
private Painter |
backgroundPainter |
private boolean |
dontIgnoreRepaint |
private Painter |
foregroundPainter |
static double |
INVERTED |
private int |
maxLineSpan |
private boolean |
multiLine |
static double |
NORMAL |
private int |
occupiedWidth |
private static String |
oldRendererKey |
private boolean |
paintBorderInsets |
boolean |
painted |
private boolean |
painting |
private int |
pHeight |
private int |
pWidth |
private JXLabel.TextAlignment |
textAlignment |
private double |
textRotation |
static double |
VERTICAL_LEFT |
static double |
VERTICAL_RIGHT |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
JXLabel()
Create a new JXLabel.
|
JXLabel(Icon image)
Creates new JXLabel with given icon.
|
JXLabel(Icon image,
int horizontalAlignment)
Creates new JXLabel with given icon and alignment.
|
JXLabel(String text)
Create a new JXLabel with the given text as the text for the label.
|
JXLabel(String text,
Icon image,
int horizontalAlignment)
Creates new JXLabel with given text, icon and alignment.
|
JXLabel(String text,
int horizontalAlignment)
Creates new JXLabel with given text and alignment.
|
Modifier and Type | Method and Description |
---|---|
private Rectangle |
calculateIconRect() |
private Point2D |
calculateT() |
Painter |
getBackgroundPainter()
Returns the current background painter.
|
Painter |
getForegroundPainter()
Returns the current foregroundPainter.
|
int |
getHeight() |
int |
getMaxLineSpan() |
protected JXLabel.MultiLineSupport |
getMultiLineSupport() |
protected int |
getOccupiedWidth() |
Dimension |
getPreferredSize() |
JXLabel.TextAlignment |
getTextAlignment()
Gets current text wrapping style.
|
double |
getTextRotation()
Gets current value of text rotation in rads.
|
private Container |
getViewport() |
int |
getWidth() |
private View |
getWrappingView() |
private void |
initLineWrapSupport()
Helper method for initializing multi line support.
|
private void |
initPainterSupport() |
boolean |
isLineWrap()
Returns the current status of line wrap support.
|
boolean |
isOpaque() |
boolean |
isPaintBorderInsets()
Returns true if the background painter should paint where the border is
or false if it should only paint inside the border.
|
protected void |
paintComponent(Graphics g) |
void |
repaint() |
void |
repaint(int x,
int y,
int width,
int height) |
void |
repaint(long tm) |
void |
repaint(long tm,
int x,
int y,
int width,
int height) |
void |
reshape(int x,
int y,
int w,
int h) |
private static int |
rotateHeight(Dimension size,
double theta) |
private static int |
rotateWidth(Dimension size,
double theta) |
void |
setBackground(Color bg) |
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.
|
void |
setForegroundPainter(Painter painter)
Sets a new foregroundPainter on the label.
|
void |
setLineWrap(boolean b)
Enables line wrapping support for plain text.
|
void |
setMaxLineSpan(int maxLineSpan) |
void |
setPaintBorderInsets(boolean paintBorderInsets)
Sets the paintBorderInsets property.
|
void |
setTextAlignment(JXLabel.TextAlignment alignment)
Sets style of wrapping the text.
|
void |
setTextRotation(double textOrientation)
Sets new value for text rotation.
|
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
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, 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
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
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, 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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public static final double NORMAL
public static final double INVERTED
public static final double VERTICAL_LEFT
public static final double VERTICAL_RIGHT
private double textRotation
private boolean painting
private Painter foregroundPainter
private Painter backgroundPainter
private boolean multiLine
private int pWidth
private int pHeight
private boolean dontIgnoreRepaint
private int occupiedWidth
private static final String oldRendererKey
private boolean paintBorderInsets
private int maxLineSpan
public boolean painted
private JXLabel.TextAlignment textAlignment
public JXLabel()
public JXLabel(Icon image)
image
- the icon to set.public JXLabel(Icon image, int horizontalAlignment)
image
- the icon to set.horizontalAlignment
- the text alignment.public JXLabel(String text)
JXLabel label = new JXLabel();
label.setText("Some Text");
text
- the text to set.public JXLabel(String text, Icon image, int horizontalAlignment)
text
- the test to set.image
- the icon to set.horizontalAlignment
- the text alignment relative to the icon.private void initPainterSupport()
private void initLineWrapSupport()
public final Painter getForegroundPainter()
public void reshape(int x, int y, int w, int h)
reshape
in class JComponent
public void setBackground(Color bg)
setBackground
in class JComponent
public void setForegroundPainter(Painter painter)
painter
- public void setBackgroundPainter(Painter p)
setBackgroundPainter
will replace that existing painter.setBackgroundPainter
in interface BackgroundPaintable
p
- the new paintergetBackgroundPainter()
public final Painter getBackgroundPainter()
getBackgroundPainter
in interface BackgroundPaintable
setBackgroundPainter(Painter)
public double getTextRotation()
setTextRotation(double)
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
private View getWrappingView()
private Container getViewport()
private Rectangle calculateIconRect()
public int getMaxLineSpan()
public void setMaxLineSpan(int maxLineSpan)
private static int rotateWidth(Dimension size, double theta)
private static int rotateHeight(Dimension size, double theta)
public void setTextRotation(double textOrientation)
textOrientation
- Value for text rotation in range <0,2PI>getTextRotation()
public void setLineWrap(boolean b)
b
- the new valuepublic boolean isLineWrap()
public JXLabel.TextAlignment getTextAlignment()
public void setTextAlignment(JXLabel.TextAlignment alignment)
alignment
- for accepted values.
public boolean isPaintBorderInsets()
isPaintBorderInsets
in interface BackgroundPaintable
public boolean isOpaque()
isOpaque
in class JComponent
public void setPaintBorderInsets(boolean paintBorderInsets)
setPaintBorderInsets
in interface BackgroundPaintable
paintBorderInsets
- new value of the paintBorderInsets propertyprotected void paintComponent(Graphics g)
paintComponent
in class JComponent
g
- graphics to paint onprivate Point2D calculateT()
public void repaint(int x, int y, int width, int height)
public void repaint(long tm, int x, int y, int width, int height)
repaint
in class JComponent
public int getHeight()
getHeight
in class JComponent
public int getWidth()
getWidth
in class JComponent
protected JXLabel.MultiLineSupport getMultiLineSupport()
protected int getOccupiedWidth()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses