|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.tbee.swing.MultiLineLabel
public class MultiLineLabel
This class is taken from O'Reilly's Java in a Nutshell volume 1
It allows for a label which displays more than one line of text.
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class javax.swing.JPanel |
|---|
javax.swing.JPanel.AccessibleJPanel |
| Nested classes/interfaces inherited from class javax.swing.JComponent |
|---|
javax.swing.JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
java.awt.Container.AccessibleAWTContainer |
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
protected int |
alignment
The default alignment of the text is LEFT |
static int |
CENTER
Used to set the alingment of the text to the center. |
static int |
LEFT
Used to set the alingment of the text to the left. |
protected int |
line_ascent
How far below the "line" a line of text extends, base on the font. |
protected int |
line_height
The height of a line of text, based on the font used to display it. |
protected int[] |
line_widths
The widths of each line of text, based on the font. |
protected java.lang.String[] |
lines
The text to display on the label. |
protected int |
margin_height
The amount of space to place around the text, top to bottom. |
protected int |
margin_width
The amount of space to place around the longest line of text, left to right. |
protected int |
max_width
The maximum width of all the lines of text, based on font. |
protected int |
num_lines
The number of individual lines of text to display on the label. |
static int |
RIGHT
Used to set the alingment of the text to the right. |
| 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 java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
MultiLineLabel(java.lang.String label)
The simplest of the constructors, all that is passed to it is the text that is to be displayed. |
|
MultiLineLabel(java.lang.String label,
int alignment)
This constructor is given the message to display and the alingment. |
|
MultiLineLabel(java.lang.String label,
int margin_width,
int margin_height)
This constructor allows the message, margin width, and margin height to be passed in. |
|
MultiLineLabel(java.lang.String label,
int margin_width,
int margin_height,
int alignment)
This constructor allows the message, margin width, margin height, and alingment to be passed set. |
|
| Method Summary | |
|---|---|
void |
addNotify()
addNotify is used by the MultiLineLabel to know when the label is set up enough to allow for the font to be measured. |
java.lang.String |
getText()
|
static void |
main(java.lang.String[] args)
|
protected void |
measure()
This protected method is used by the MultiLineLabel to measure the amount of space which will be required to display the text, given whatever font we are displaying it in. |
java.awt.Dimension |
minimumSize()
minimumSize is used by the layout manager to determine the minimum amount of space need to display the text. |
protected void |
newLabel(java.lang.String label)
This protected method is called by the MultiLineLabel to set up the text for display. |
void |
paint(java.awt.Graphics g)
paint is the method which is called by the layout manager to draw the MultiLineLabel, with text to the screen. |
java.awt.Dimension |
preferredSize()
preferredSize is used by the layout manager to determine how much space the MultiLineLabel needs to display itself properly. |
void |
setAlignment(int a)
This method allows for the alignment to be set, after the alingment is set the label is redisplayed by calling the repaint method. |
void |
setFont(java.awt.Font font)
Set the font to be used to display the text. |
void |
setForeground(java.awt.Color color)
This method allows the text color to be changed. |
void |
setLabel(java.lang.String label)
Set the label to display. |
void |
setMarginHeight(int mh)
The margin height, specifies the amount of space from the top and bottom most line to the edge of the label. |
void |
setMarginWidth(int mw)
The margin width, specifies the amount of space from the two ends of the longest line of text, to the edge of the label. |
| Methods inherited from class javax.swing.JPanel |
|---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class javax.swing.JComponent |
|---|
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, 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, 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, paintComponents, 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, 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, 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 |
|---|
public static final int LEFT
public static final int CENTER
public static final int RIGHT
protected java.lang.String[] lines
protected int num_lines
protected int margin_width
protected int margin_height
protected int line_height
protected int line_ascent
protected int[] line_widths
protected int max_width
protected int alignment
| Constructor Detail |
|---|
public MultiLineLabel(java.lang.String label)
label - The text to display, as a String.
public MultiLineLabel(java.lang.String label,
int alignment)
label - The text to display, as a String.alignment - The alignment to display the text.
public MultiLineLabel(java.lang.String label,
int margin_width,
int margin_height)
label - The text to display, as a String.margin_width - The margin width to use while displaying the text.margin_height - The margin height to use while displaying the text.
public MultiLineLabel(java.lang.String label,
int margin_width,
int margin_height,
int alignment)
label - The text to display, as a String.margin_width - The margin width to use while displaying the text.margin_height - The margin height to use while displaying the text.alignment - The alingment to use while displaying the text.| Method Detail |
|---|
public void addNotify()
addNotify in class javax.swing.JComponentpublic java.awt.Dimension minimumSize()
minimumSize in class java.awt.Containerpublic void paint(java.awt.Graphics g)
paint in class javax.swing.JComponentg - The Graphics to draw upon.protected void measure()
protected void newLabel(java.lang.String label)
label - The text to be displayed.public java.awt.Dimension preferredSize()
preferredSize in class java.awt.Containerpublic void setAlignment(int a)
a - The alingment to use when displaying the text. Passed using
the static ints defined in this class.public void setFont(java.awt.Font font)
setFont in class javax.swing.JComponentfont - The Font to use.public void setForeground(java.awt.Color color)
setForeground in class javax.swing.JComponentcolor - The Color to display the text in.public void setLabel(java.lang.String label)
label - The text to display, passed in as a String.public java.lang.String getText()
public void setMarginHeight(int mh)
mh - The margin height, in the form of an integer.public void setMarginWidth(int mw)
mw - The margin width, in the form of an integer.
public static void main(java.lang.String[] args)
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||