|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JLabel com.jidesoft.swing.StyledLabel
public class StyledLabel
StyledLabel
is a special JLabel which can display text in different styles. It is a component between
JLabel and JTextPane. JLabel is simple, fast but has limited features. For example, you can't use different color to
draw the text. You may argue JLabel can use HTML tag to display text in different colors. However there are two main
reasons to use StyledLabel. First of all, StyledLabel is very fast and almost as fast as JLabel with plain text. HTML
JLabel is very slow. You can see StyledLabelPerformanceDemo.java in examples\B15. StyledLabel folder to see a
performace test of HTML JLabel and StyledLabel. HTML JLabel is also buggy. See bug report at http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4373575.
Sun claimed it is fixed but it is not as another user pointed it out at the end. If you run the test case provided by
original submitter, you will immediately notice the tree node disappeared when you click on the tree nodes. This bug
is actually one of the main reasons we decided to create StyledLabel. JTextPane is powerful and can display text in
different color. But in the cases like cell renderer, JTextPane is obviously an overkill.
addStyleRange(StyleRange)
, setStyleRanges(StyleRange[])
, clearStyleRange(StyleRange)
, and clearStyleRanges()
.
This is one thing about StyleRange that you should be aware of, which could be considered as a future enhancement
item, is that the StyleRanges can't overlap with each other. For example, if you defined a StyleRange that covers
from index 0 to index 3, you can't define any other StyleRange that overlaps with the first one. If you do so, the
second StyleRange will be ignored.
We borrowed some ideas from SWT's StyledText when we designed StyledLabel, especially StyleRange concept. Saying
that, the features of the two components are not exactly the same since the purpose of the two components are quite
different.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JLabel |
---|
JLabel.AccessibleJLabel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static String |
PROPERTY_IGNORE_COLOR_SETTINGS
|
static String |
PROPERTY_STYLE_RANGE
|
Fields inherited from class javax.swing.JLabel |
---|
labelFor |
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 javax.swing.SwingConstants |
---|
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
StyledLabel()
|
|
StyledLabel(Icon image)
|
|
StyledLabel(Icon image,
int horizontalAlignment)
|
|
StyledLabel(String text)
|
|
StyledLabel(String text,
Icon icon,
int horizontalAlignment)
|
|
StyledLabel(String text,
int horizontalAlignment)
|
Method Summary | |
---|---|
void |
addStyleRange(StyleRange styleRange)
Adds a StyleRange into this StyledLabel . |
void |
addStyleRanges(StyleRange[] styleRanges)
Adds a list of StyleRanges into this StyledLabel . |
void |
clearStyleRange(StyleRange styleRange)
Removes the StyleRange. |
void |
clearStyleRanges()
Clears all the StyleRanges. |
Dimension |
getMaximumSize()
|
int |
getMaxRows()
Gets the maximum rows possible after wrapping. |
Dimension |
getMinimumSize()
|
int |
getMinRows()
Gets the minimum rows possible after wrapping. |
int |
getPreferredWidth()
Gets the preferred width of the styled label. |
int |
getRowGap()
Gets the gap pixels between rows. |
int |
getRows()
Gets the default row count to wrap the StyledLabel . |
StyleRange[] |
getStyleRanges()
Gets the array of StyledText. |
String |
getUIClassID()
Returns a string that specifies the name of the L&F class that renders this component. |
boolean |
isIgnoreColorSettings()
StyleRange could define color for the text and lines. |
boolean |
isLineWrap()
Gets the flag indicating if the line should be automatically wrapped when the column width is limited. |
boolean |
isTruncated()
Gets the status indicating if the StyledLabel is painted truncated. |
void |
setIgnoreColorSettings(boolean ignoreColorSettings)
Sets if the color defined by StyleRange should be ignored. |
void |
setLineWrap(boolean lineWrap)
Sets the flag indicating if the line should be automatically wrapped when the column width is limited. |
void |
setMaxRows(int maxRows)
Sets the maximum rows possible after wrapping. |
void |
setMinRows(int minRows)
Sets the minimum rows possible after wrapping. |
void |
setPreferredWidth(int preferredWidth)
Sets the preferred width of the styled label. |
void |
setRowGap(int rowGap)
Sets the gap pixels between rows. |
void |
setRows(int rows)
Sets the default row count to wrap the StyledLabel . |
void |
setStyleRanges(StyleRange[] styleRanges)
Clears all the old StyleRanges and adds a list of StyleRanges into this StyledLabel . |
void |
setTruncated(boolean truncated)
It will be invoked by BasicStyledLabelUI each time the StyledLabel is painted. |
void |
updateUI()
Resets the UI property to a value from the current look and feel. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String PROPERTY_STYLE_RANGE
public static final String PROPERTY_IGNORE_COLOR_SETTINGS
Constructor Detail |
---|
public StyledLabel()
public StyledLabel(Icon image)
public StyledLabel(Icon image, int horizontalAlignment)
public StyledLabel(String text)
public StyledLabel(String text, int horizontalAlignment)
public StyledLabel(String text, Icon icon, int horizontalAlignment)
Method Detail |
---|
public void updateUI()
updateUI
in class JLabel
JComponent.updateUI()
public String getUIClassID()
getUIClassID
in class JLabel
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public void addStyleRange(StyleRange styleRange)
StyledLabel
.
styleRange
- the new StyleRange.public void setStyleRanges(StyleRange[] styleRanges)
StyledLabel
.
styleRanges
- set the StyleRanges.public void addStyleRanges(StyleRange[] styleRanges)
StyledLabel
.
styleRanges
- an array of StyleRanges.public StyleRange[] getStyleRanges()
public void clearStyleRange(StyleRange styleRange)
styleRange
- the StyleRange to be removed.public void clearStyleRanges()
public boolean isIgnoreColorSettings()
public void setIgnoreColorSettings(boolean ignoreColorSettings)
ignoreColorSettings
- true or false.public Dimension getMinimumSize()
getMinimumSize
in class JComponent
public Dimension getMaximumSize()
getMaximumSize
in class JComponent
public void setPreferredWidth(int preferredWidth)
preferredWidth
- the preferred widthpublic int getPreferredWidth()
public boolean isLineWrap()
public void setLineWrap(boolean lineWrap)
lineWrap
- the flagpublic int getRows()
StyledLabel
.
setRows(int)
public void setRows(int rows)
StyledLabel
.
By default, the value is 0. Any non-positive value is deemed as not configured.
This has lower priority than setPreferredWidth(int)
. If preferred width is set, this flag does not take
effect.
rows
- the row countpublic int getRowGap()
setRowGap(int)
public void setRowGap(int rowGap)
rowGap
- the gap pixels.public int getMaxRows()
public void setMaxRows(int maxRows)
maxRows
- the maximum rowspublic int getMinRows()
public void setMinRows(int minRows)
minRows
- the minimum rowspublic boolean isTruncated()
public void setTruncated(boolean truncated)
BasicStyledLabelUI
each time the StyledLabel is painted.
Please do NOT try to call this method to change the flag and NOT expect the setting could change the behavior of
isTruncated()
.
truncated
- the flag
|
JIDE 3.5.15 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |