|
Eclipse Platform 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.eclipse.swt.widgets.Widget | +--org.eclipse.swt.widgets.Control | +--org.eclipse.swt.widgets.Scrollable | +--org.eclipse.swt.widgets.Composite | +--org.eclipse.swt.widgets.Canvas | +--org.eclipse.swt.custom.CLabel
A Label which supports aligned text and/or an image and different border styles.
If there is not enough space a CLabel uses the following strategy to fit the information into the available space:
ignores the indent in left align mode ignores the image and the gap shortens the text by replacing the center portion of the label with an ellipsis shortens the text by removing the center portion of the label
Field Summary |
Fields inherited from class org.eclipse.swt.widgets.Control |
handle |
Constructor Summary | |
CLabel(Composite parent,
int style)
Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. |
Method Summary | |
Point |
computeSize(int wHint,
int hHint,
boolean changed)
Returns the preferred size of the receiver. |
int |
getAlignment()
Returns the alignment. |
Image |
getImage()
Return the CLabel's image or null . |
String |
getText()
Return the Label's text. |
String |
getToolTipText()
Returns the receiver's tool tip text, or null if it has not been set. |
void |
setAlignment(int align)
Set the alignment of the CLabel. |
void |
setBackground(Color[] colors,
int[] percents)
Specify a gradiant of colours to be draw in the background of the CLabel. |
void |
setBackground(Image image)
Set the image to be drawn in the background of the label. |
void |
setFont(Font font)
Sets the font that the receiver will use to paint textual information to the font specified by the argument, or to the default font for that kind of control if the argument is null. |
void |
setImage(Image image)
Set the label's Image. |
void |
setText(String text)
Set the label's text. |
void |
setToolTipText(String string)
Sets the receiver's tool tip text to the argument, which may be null indicating that no tool tip text should be shown. |
protected String |
shortenText(GC gc,
String t,
int width)
Shorten the given text t so that its length doesn't exceed
the given width. |
Methods inherited from class org.eclipse.swt.widgets.Canvas |
getCaret, scroll, setCaret |
Methods inherited from class org.eclipse.swt.widgets.Composite |
checkSubclass, getChildren, getLayout, getTabList, layout, layout, setFocus, setLayout, setTabList |
Methods inherited from class org.eclipse.swt.widgets.Scrollable |
computeTrim, getClientArea, getHorizontalBar, getVerticalBar |
Methods inherited from class org.eclipse.swt.widgets.Widget |
addDisposeListener, addListener, checkWidget, dispose, getData, getData, getStyle, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, setData, setData, toString |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public CLabel(Composite parent, int style)
The style value is either one of the style constants defined in
class SWT
which is applicable to instances of this
class, or must be built by bitwise OR'ing together
(that is, using the int
"|" operator) two or more
of those SWT
style constants. The class description
lists the style constants that are applicable to the class.
Style bits are also inherited from superclasses.
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to construct
IllegalArgumentException
- SWTException
- SWT.LEFT
,
SWT.RIGHT
,
SWT.CENTER
,
SWT.SHADOW_IN
,
SWT.SHADOW_OUT
,
SWT.SHADOW_NONE
,
Widget.getStyle()
Method Detail |
public Point computeSize(int wHint, int hHint, boolean changed)
Control
The preferred size of a control is the size that it would
best be displayed at. The width hint and height hint arguments
allow the caller to ask a control questions such as "Given a particular
width, how high does the control need to be to show all of the contents?"
To indicate that the caller does not wish to constrain a particular
dimension, the constant SWT.DEFAULT
is passed for the hint.
If the changed flag is true
, it indicates that the receiver's
contents have changed, therefore any caches that a layout manager
containing the control may have been keeping need to be flushed. When the
control is resized, the changed flag will be false
, so layout
manager caches can be retained.
computeSize
in class Composite
wHint
- the width hint (can be SWT.DEFAULT
)hHint
- the height hint (can be SWT.DEFAULT
)changed
- true
if the control's contents have changed, and false
otherwise
Layout
,
Control.getBorderWidth()
,
Control.getBounds()
,
Control.getSize()
,
Control.pack()
,
"computeTrim, getClientArea for controls that implement them"public int getAlignment()
public Image getImage()
null
.
public void setToolTipText(String string)
Control
setToolTipText
in class Control
string
- the new tool tip text (or null)public String getText()
public String getToolTipText()
Control
getToolTipText
in class Control
public void setAlignment(int align)
align
- the alignment style of LEFT, RIGHT or CENTER
SWTException
- public void setBackground(Color[] colors, int[] percents)
clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), display.getSystemColor(SWT.COLOR_BLUE), display.getSystemColor(SWT.COLOR_WHITE), display.getSystemColor(SWT.COLOR_WHITE)}, new int[] {25, 50, 100});
colors
- an array of Color that specifies the colors to appear in the gradiant
in order of appearance left to right. The value null
clears the
background gradiant. The value null
can be used inside the array of
Color to specify the background color.percents
- an array of integers between 0 and 100 specifying the percent of the width
of the widget at which the color should change. The size of the percents array must be one
less than the size of the colors array.
SWTException
- public void setBackground(Image image)
image
- the image to be drawn in the background
SWTException
- public void setFont(Font font)
Control
setFont
in class Canvas
font
- the new font (or null)public void setImage(Image image)
null
clears it.
image
- the image to be displayed in the label or null
SWTException
- public void setText(String text)
null
clears it.
text
- the text to be displayed in the label or null
SWTException
- protected String shortenText(GC gc, String t, int width)
t
so that its length doesn't exceed
the given width. The default implementation replaces characters in the
center of the original string with an ellipsis ("...").
Override if you need a different strategy.
|
Eclipse Platform 2.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |