public class MultiLineLabel extends JComponent
MultiLineLabel
may be used in place of javax.swing.JLabel. setMaxWidth()
explicitly. If this is not set,
MultiLineLabel
will derive its width from the parent component.JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected int |
alignment |
static int |
CENTER |
static int |
DEFAULT_ALIGN |
static int |
DEFAULT_MARGIN |
private static int |
DONE |
private static int |
FOUND |
protected String |
labelText |
static int |
LEAST_ALLOWED |
static int |
LEFT |
protected Vector |
line |
protected int |
lineAscent |
protected int |
lineDescent |
protected int |
lineHeight |
protected int[] |
lineWidth |
protected int |
marginHeight |
protected int |
marginWidth |
private int |
maxAllowed |
private boolean |
maxAllowedSet |
protected int |
maxWidth |
private static char |
NEW_LINE |
private static int |
NOT_DONE |
private static int |
NOT_FOUND |
protected int |
numLines |
static int |
RIGHT |
private static long |
serialVersionUID |
private static char[] |
SPACES |
private static char[] |
WHITE_SPACE |
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
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
MultiLineLabel(String label)
Constructor using default max-width, alignment, and margin.
|
MultiLineLabel(String label,
int alignment)
Constructor using default max-width, and margin.
|
MultiLineLabel(String label,
int marginWidth,
int marginHeight)
Constructor using default max-width and alignment.
|
MultiLineLabel(String text,
int horMargin,
int vertMargin,
int maxWidth,
int justify)
Constructor
|
Modifier and Type | Method and Description |
---|---|
void |
addNotify()
This method is called by the system after this object is first created.
|
(package private) int |
breakWord(String word,
FontMetrics fm)
This method scans the input string until the max allowed width is reached.
|
private void |
divideLabel()
This method breaks the label text up into multiple lines of text.
|
int |
getAlignment()
This method may be used to retrieve the text alignment for the label
|
int |
getMarginHeight()
This method may be used to retrieve the vertical margin for the label
|
int |
getMarginWidth()
This method may be used to retrieve the horizontal margin for the label
|
Dimension |
getMinimumSize()
This method is typically used by the layout manager, it reports the absolute minimum space
required to display the entire label.
|
(package private) int |
getPosition(String target,
int start,
char[] source,
int mode)
This method searches the target string for occurences of any of the characters in the source
string.
|
Dimension |
getPreferredSize()
This method is typically used by the layout manager, it reports the necessary space to
display the label comfortably.
|
protected void |
measure()
This method finds the font size, each line width and the widest line.
|
void |
paint(Graphics graphics)
This method draws the label.
|
void |
setBounds(int x,
int y,
int width,
int height)
Moves and resizes this component.
|
void |
setColor(Color color)
This method may be used to set the color in which the text should be drawn
|
void |
setFont(Font font)
This method may be used to set the font that should be used to draw the label
|
void |
setJustify(int alignment)
This method may be used to set the text alignment for the label
|
void |
setMarginHeight(int margin)
This method may be used to set the vertical margin for the label
|
void |
setMarginWidth(int margin)
This method may be used to set the horizontal margin
|
void |
setMaxWidth(int width)
This method may be used to set the max allowed line width
|
void |
setText(String labelText)
This method may be used to set the label text
|
addAncestorListener, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
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, getAccessibleContext, 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, imageUpdate, 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, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private static final long serialVersionUID
public static final int LEFT
public static final int CENTER
public static final int RIGHT
public static final int DEFAULT_MARGIN
public static final int DEFAULT_ALIGN
public static final int LEAST_ALLOWED
private static final int FOUND
private static final int NOT_FOUND
private static final int NOT_DONE
private static final int DONE
private static final char[] WHITE_SPACE
private static final char[] SPACES
private static final char NEW_LINE
protected int numLines
protected int marginHeight
protected int marginWidth
protected int lineHeight
protected int lineAscent
protected int lineDescent
protected int[] lineWidth
protected int maxWidth
private int maxAllowed
private boolean maxAllowedSet
protected int alignment
public MultiLineLabel(String text, int horMargin, int vertMargin, int maxWidth, int justify)
text
- the text to be displayedhorMargin
- the horizontal margin for the labelvertMargin
- the vertical margin for the labelmaxWidth
- the maximum allowed width of the textjustify
- the text alignment for the labelpublic MultiLineLabel(String label, int marginWidth, int marginHeight)
label
- the text to be displayedmarginWidth
- the horizontal margin for the labelmarginHeight
- the vertical margin for the labelpublic MultiLineLabel(String label, int alignment)
label
- the text to be displayedalignment
- the text alignment for the labelpublic MultiLineLabel(String label)
label
- the text to be displayedint getPosition(String target, int start, char[] source, int mode)
target
- the text to be searchedstart
- the start position for the searchsource
- the list of characters to be searched formode
- the search mode FOUND = reports first found NOT_FOUND = reports first not foundint breakWord(String word, FontMetrics fm)
word
- word to breakprivate void divideLabel()
protected void measure()
public void paint(Graphics graphics)
paint
in class JComponent
graphics
- the device contextpublic void setText(String labelText)
labelText
- the text to be displayedpublic void setFont(Font font)
setFont
in class JComponent
font
- font to be used within the labelpublic void setColor(Color color)
color
- the text colorpublic void setJustify(int alignment)
alignment
- the alignment, possible values are LEFT, CENTER, RIGHTpublic void setMaxWidth(int width)
width
- the max allowed line width in pixelspublic void setMarginWidth(int margin)
margin
- the margin to the left and to the right of the labelpublic void setMarginHeight(int margin)
margin
- the margin on the top and bottom of the labelpublic void setBounds(int x, int y, int width, int height)
x
and y
, and the new size is specified by width
and height
.public int getAlignment()
public int getMarginWidth()
public int getMarginHeight()
public Dimension getPreferredSize()
getPreferredSize
in class JComponent
public Dimension getMinimumSize()
getMinimumSize
in class JComponent
public void addNotify()
addNotify
in class JComponent
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses