public class ColouredLabel extends JLabel
It allows easily setting the text colour and the background colour of the label.
Now you don't have to override paint.
JLabel.AccessibleJLabel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected Color |
backColour_
Description of the Field
|
protected String |
boldOff_
Description of the Field
|
protected String |
boldOn_
Description of the Field
|
private static String |
DEFAULT_FONT_FACE |
protected int |
fontMidpoint_
Description of the Field
|
protected String |
fontName_
Description of the Field
|
protected String |
fontSize_
Description of the Field
|
protected String[] |
fontSizes_
Description of the Field
|
protected String |
italicOff_
Description of the Field
|
protected String |
italicOn_
Description of the Field
|
protected String |
labelText_
Description of the Field
|
(package private) Log |
log_ |
protected Color |
textColour_
Description of the Field
|
protected short |
wrapCharWidth_
how many characters in the text before a wrap.
|
protected boolean |
wrapText_
Flags if this text gets wrapped.
|
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 |
---|
ColouredLabel(Color backColour,
Color textColour,
Font newFont,
String labelText)
Constructor to set up the Label with the specified colours.
|
ColouredLabel(Color backColour,
Color textColour,
Font newFont,
String labelText,
boolean wrapText)
Constructor to set up the Label with the specified colours.
|
ColouredLabel(Color backColour,
Color textColour,
String labelText)
Constructor to set up the Label with the specified colours.
|
ColouredLabel(Color backColour,
Color textColour,
String labelText,
boolean wrapText)
Constructor to set up the Label with the specified colours.
|
ColouredLabel(Color textColour,
String labelText)
Constructor to set up the Label with the specified colour.
|
ColouredLabel(String labelText)
Basic constructor to set up the Label with the specified colour.
|
Modifier and Type | Method and Description |
---|---|
private String |
addWrap(String text,
short wrapChars) |
private void |
coloursChanged()
Refreshes the text string with some new colour values.
|
Color |
getBackColour()
Get method for the current Background Colour being used in this label.
|
private String |
getBackColourHtmlString()
Get the HTML string representing the Current Background Colour.
|
Color |
getTextColour()
Get method for the current Text Colour being used in this label.
|
private String |
getTextColourHtmlString()
Get the HTML string representing the Current Text Colour.
|
String |
getTextColourHtmlString(Color c)
Get the HTML string representing the specified Color.
|
static void |
main(String[] args) |
void |
setBackColour(Color backColour)
Sets the current background Text Colour being used in this label.
|
void |
setFont(Font newFont)
Allows setting of the Font to use in this label.
|
void |
setFontName(String fontName)
A convienience method to directly set the Font using the face name
instead of sending a Font object.
|
void |
setText(String newText)
Overrides the JLabel setText to add the extra stuff to get the extra
colours and font stuff.
|
void |
setTextColour(Color textColour)
Sets the current Text Colour being used in this label.
|
void |
setWrapCharWidth(short numChars)
Set the number of chars before it fits in a wrap by inserting a
. |
void |
setWrapText(boolean wrapText)
Forces the display of the label text to the specified wrapping.
|
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, 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, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, 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, 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, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
private static final String DEFAULT_FONT_FACE
protected Color textColour_
protected Color backColour_
protected String labelText_
protected String[] fontSizes_
protected int fontMidpoint_
protected String italicOff_
protected boolean wrapText_
protected short wrapCharWidth_
public ColouredLabel(String labelText)
labelText
- the text in the labelpublic ColouredLabel(Color textColour, String labelText)
textColour
- is the Color to use in the text in the labellabelText
- the text in the labelpublic ColouredLabel(Color backColour, Color textColour, String labelText)
backColour
- is the Color to use in the back of the labeltextColour
- is the Color to use in the text in the labellabelText
- the text in the labelpublic ColouredLabel(Color backColour, Color textColour, String labelText, boolean wrapText)
backColour
- is the Color to use in the back of the labeltextColour
- is the Color to use in the text in the labellabelText
- the text in the labelpublic ColouredLabel(Color backColour, Color textColour, Font newFont, String labelText)
backColour
- is the Color to use in the back of the labeltextColour
- is the Color to use in the text in the labelnewFont
- is the Font to use in the text in the labellabelText
- the text in the labelpublic ColouredLabel(Color backColour, Color textColour, Font newFont, String labelText, boolean wrapText)
backColour
- is the Color to use in the back of the labeltextColour
- is the Color to use in the text in the labelnewFont
- is the Font to use in the text in the labellabelText
- the text in the labelpublic void setWrapCharWidth(short numChars)
.numChars
- the number of chars before it fits in a wrappublic void setWrapText(boolean wrapText)
wrapText
- flags if the text in the label will wrap or notpublic void setText(String newText)
public void setFont(Font newFont)
setFont
in class JComponent
newFont
- the new font to use for this ColouredLabel.public void setFontName(String fontName)
fontName
- The new fontName valuepublic void setTextColour(Color textColour)
textColour
- the current Text Colour to use in this label.public void setBackColour(Color backColour)
backColour
- the current background Colour to use in this label.public Color getTextColour()
public Color getBackColour()
private String getTextColourHtmlString()
private String getBackColourHtmlString()
public String getTextColourHtmlString(Color c)
c
- is the Color to retrieve the html string for.private void coloursChanged()
WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses