CLabel

A Label which supports aligned text and/or an image and different border styles. <p> If there is not enough space a CLabel uses the following strategy to fit the information into the available space: <pre> 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 </pre> <p> <dl> <dt><b>Styles:</b> <dd>LEFT, RIGHT, CENTER, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> <dt><b>Events:</b> <dd></dd> </dl>

</p><p> IMPORTANT: This class is <em>not</em> intended to be subclassed. </p>

@see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample</a> @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>

Constructors

this
this(Composite parent, int style)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance. <p> The style value is either one of the style constants defined in class <code>SWT</code> which is applicable to instances of this class, or must be built by <em>bitwise OR</em>'ing together (that is, using the <code>int</code> "|" operator) two or more of those <code>SWT</code> style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses. </p>

Members

Functions

getAlignment
int getAlignment()

Returns the alignment. The alignment style (LEFT, CENTER or RIGHT) is returned.

getImage
Image getImage()

Return the CLabel's image or <code>null</code>.

getText
String getText()

Return the Label's text.

setAlignment
void setAlignment(int align_)

Set the alignment of the CLabel. Use the values LEFT, CENTER and RIGHT to align image and text within the available space.

setBackground
void setBackground(Color[] colors, int[] percents)

Specify a gradient of colours to be drawn in the background of the CLabel. <p>For example, to draw a gradient that varies from dark blue to blue and then to white and stays white for the right half of the label, use the following call to setBackground:</p> <pre> 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}); </pre>

setBackground
void setBackground(Color[] colors, int[] percents, bool vertical)

Specify a gradient of colours to be drawn in the background of the CLabel. <p>For example, to draw a gradient that varies from dark blue to white in the vertical, direction use the following call to setBackground:</p> <pre> clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE), display.getSystemColor(SWT.COLOR_WHITE)}, new int[] {100}, true); </pre>

setBackground
void setBackground(Image image)

Set the image to be drawn in the background of the label.

setImage
void setImage(Image image)

Set the label's Image. The value <code>null</code> clears it.

setText
void setText(String text)

Set the label's text. The value <code>null</code> clears it.

shortenText
String shortenText(GC gc, String t, int width)

Shorten the given text <code>t</code> 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.

Inherited Members

From Canvas

drawBackground
void drawBackground(GC gc, int x, int y, int width, int height)

Fills the interior of the rectangle specified by the arguments, with the receiver's background.

getCaret
Caret getCaret()

Returns the caret. <p> The caret for the control is automatically hidden and shown when the control is painted or resized, when focus is gained or lost and when an the control is scrolled. To avoid drawing on top of the caret, the programmer must hide and show the caret when drawing in the window any other time. </p>

getIME
IME getIME()

Returns the IME.

scroll
void scroll(int destX, int destY, int x, int y, int width, int height, bool all)

Scrolls a rectangular area of the receiver by first copying the source area to the destination and then causing the area of the source which is not covered by the destination to be repainted. Children that intersect the rectangle are optionally moved during the operation. In addition, outstanding paint events are flushed before the source area is copied to ensure that the contents of the canvas are drawn correctly.

setCaret
void setCaret(Caret caret)

Sets the receiver's caret. <p> The caret for the control is automatically hidden and shown when the control is painted or resized, when focus is gained or lost and when an the control is scrolled. To avoid drawing on top of the caret, the programmer must hide and show the caret when drawing in the window any other time. </p> @param caret the new caret for the receiver, may be null

setIME
void setIME(IME ime)

Sets the receiver's IME.

Meta