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
This class may be subclassed for the purpose of overriding the default string
shortening algorithm that is implemented in method shortenText().
CLabel#shortenText(GC, String, int)
| Modifier and Type | Field and Description |
|---|---|
| private int | align
the alignment. |
| private String | |
| private Color | |
| private Image | |
| private int | |
| private static final int | DEFAULT_MARGIN
Left and right margins |
| private static int | |
| private static final String | ELLIPSIS
a string inserted in the middle of text that has been shortened |
| private static final int | GAP
Gap between icon and text |
| private Color[] | |
| private int[] | |
| private boolean | |
| private boolean | |
| private Image | image
the current icon |
| private int | |
| private int | |
| private String | text
the current text |
| private int |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv char | |
| private static int | checkStyle(int style)
Check the style bits to ensure that no invalid styles are applied.
|
| public Point | computeSize(int
the width hint (can be wHint, int SWT.DEFAULT)the height hint (can be hHint, boolean SWT.DEFAULT)true if the control's contents have changed, and false otherwiseOverrides org. |
| private void | drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright)
Draw a rectangle in the given colors. |
| public int | |
| public int | |
| public Image | |
| public int | |
| public int | |
| public int | getStyle()
Overrides org. |
| public String | |
| public String | getToolTipText()
Returns the receiver's tool tip text, or null if it has
not been set.
|
| public int | |
| private Point | |
| private void | |
| pack-priv void | |
| pack-priv void | |
| pack-priv void | |
| private void | |
| public void | setAlignment(int
the alignment style of LEFT, RIGHT or CENTER align)Set the horizontal alignment of the CLabel. |
| public void | setBackground(Color
the new color (or null) color)
Sets the receiver's background color to the color specified
by the argument, or to the default system color for the control
if the argument is null.
|
| public void | setBackground(Color[]
an array of Color that specifies the colors to appear in the gradient
in order of appearance from left to right; The value colors, int[] null
clears the background gradient; the value null can be used
inside the array of Color to specify the background color.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. percents)Specify a gradient of colours to be drawn in the background of the CLabel. |
| public void | setBackground(Color[]
an array of Color that specifies the colors to appear in the gradient
in order of appearance from left/top to right/bottom; The value colors, int[] null
clears the background gradient; the value null can be used
inside the array of Color to specify the background color.an array of integers between 0 and 100 specifying the percent of the width/height
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. percents, boolean indicate the direction of the gradient. True is vertical and false is horizontal. vertical)Specify a gradient of colours to be drawn in the background of the CLabel. |
| public void | setBackground(Image
the image to be drawn in the background image)Set the image to be drawn in the background of the label. |
| public void | setBottomMargin(int
the bottom margin of the label, which must be equal to or greater than zero bottomMargin)Set the label's bottom margin, in points. |
| public void | setFont(Font
the new font (or null) font)Overrides org. |
| public void | |
| public void | setLeftMargin(int
the left margin of the label, which must be equal to or greater than zero leftMargin)Set the label's horizontal left margin, in points. |
| public void | setMargins(int
the left margin. leftMargin, int the top margin. topMargin, int the right margin. rightMargin, int the bottom margin. bottomMargin)Set the label's margins, in points. |
| public void | setRightMargin(int
the right margin of the label, which must be equal to or greater than zero rightMargin)Set the label's right margin, in points. |
| public void | |
| public void | setToolTipText(String
the new tool tip text (or null) string)
Sets the receiver's tool tip text to the argument, which
may be null indicating that the default tool tip for the
control will be shown.
|
| public void | setTopMargin(int
the top margin of the label, which must be equal to or greater than zero topMargin)Set the label's top margin, in points. |
| protected String | Returns: the shortened textthe gc to use for text measurement gc, String the text to shorten t, int the width to shorten the text to, in points width)Shorten the given text |
| private String[] | |
| pack-priv int |
| align | back to summary |
|---|---|
| private int align the alignment. Either CENTER, RIGHT, LEFT. Default is LEFT | |
| appToolTipText | back to summary |
|---|---|
| private String appToolTipText | |
| background | back to summary |
|---|---|
| private Color background | |
| backgroundImage | back to summary |
|---|---|
| private Image backgroundImage | |
| bottomMargin | back to summary |
|---|---|
| private int bottomMargin | |
| DEFAULT_MARGIN | back to summary |
|---|---|
| private static final int DEFAULT_MARGIN Left and right margins | |
| DRAW_FLAGS | back to summary |
|---|---|
| private static int DRAW_FLAGS | |
| ELLIPSIS | back to summary |
|---|---|
| private static final String ELLIPSIS a string inserted in the middle of text that has been shortened | |
| GAP | back to summary |
|---|---|
| private static final int GAP Gap between icon and text | |
| gradientColors | back to summary |
|---|---|
| private Color[] gradientColors | |
| gradientPercents | back to summary |
|---|---|
| private int[] gradientPercents | |
| gradientVertical | back to summary |
|---|---|
| private boolean gradientVertical | |
| ignoreDispose | back to summary |
|---|---|
| private boolean ignoreDispose | |
| image | back to summary |
|---|---|
| private Image image the current icon | |
| leftMargin | back to summary |
|---|---|
| private int leftMargin | |
| rightMargin | back to summary |
|---|---|
| private int rightMargin | |
| text | back to summary |
|---|---|
| private String text the current text | |
| topMargin | back to summary |
|---|---|
| private int topMargin | |
| CLabel | back to summary |
|---|---|
| public CLabel(Composite parent, int style) Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.
The style value is either one of the style constants defined in
class
| |
| _findMnemonic | back to summary |
|---|---|
| pack-priv char _findMnemonic(String string) | |
| checkStyle | back to summary |
|---|---|
| private static int checkStyle(int style) Hides org. Check the style bits to ensure that no invalid styles are applied. | |
| computeSize | back to summary |
|---|---|
| public Point computeSize(int wHint, int hHint, boolean changed) Overrides org. Doc from org. Returns the preferred size (in points) of the receiver.
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
If the changed flag is | |
| drawBevelRect | back to summary |
|---|---|
| private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topleft, Color bottomright) Draw a rectangle in the given colors. | |
| getAlignment | back to summary |
|---|---|
| public int getAlignment() Returns the horizontal alignment. The alignment style (LEFT, CENTER or RIGHT) is returned.
| |
| getBottomMargin | back to summary |
|---|---|
| public int getBottomMargin() Return the CLabel's bottom margin.
| |
| getImage | back to summary |
|---|---|
| public Image getImage() Return the CLabel's image or
| |
| getLeftMargin | back to summary |
|---|---|
| public int getLeftMargin() Return the CLabel's left margin.
| |
| getRightMargin | back to summary |
|---|---|
| public int getRightMargin() Return the CLabel's right margin.
| |
| getStyle | back to summary |
|---|---|
| public int getStyle() Overrides org. Doc from org. Returns the receiver's style information.
Note that the value which is returned by this method may
not match the value which was provided to the constructor
when the receiver was created. This can occur when the underlying
operating system does not support a particular combination of
requested styles. For example, if the platform widget used to
implement a particular SWT widget always has scroll bars, the
result of calling this method would always have the
| |
| getText | back to summary |
|---|---|
| public String getText() Return the Label's text.
| |
| getToolTipText | back to summary |
|---|---|
| public String getToolTipText() Overrides org. Doc from org. Returns the receiver's tool tip text, or null if it has not been set. | |
| getTopMargin | back to summary |
|---|---|
| public int getTopMargin() Return the CLabel's top margin.
| |
| getTotalSize | back to summary |
|---|---|
| private Point getTotalSize(Image image, String text) Compute the minimum size. | |
| initAccessible | back to summary |
|---|---|
| private void initAccessible() | |
| onDispose | back to summary |
|---|---|
| pack-priv void onDispose(Event event) | |
| onMnemonic | back to summary |
|---|---|
| pack-priv void onMnemonic(TraverseEvent event) | |
| onPaint | back to summary |
|---|---|
| pack-priv void onPaint(PaintEvent event) | |
| paintBorder | back to summary |
|---|---|
| private void paintBorder(GC gc, Rectangle r) Paint the Label's border. | |
| setAlignment | back to summary |
|---|---|
| public void setAlignment(int align) Set the horizontal alignment of the CLabel. Use the values LEFT, CENTER and RIGHT to align image and text within the available space.
| |
| setBackground | back to summary |
|---|---|
| public void setBackground(Color color) Overrides org. Doc from org. Sets the receiver's background color to the color specified by the argument, or to the default system color for the control if the argument is null. Note This operation is a hint and may be overridden by the platform. | |
| setBackground | back to summary |
|---|---|
| public void setBackground(Color[] colors, int[] percents) Specify a gradient of colours to be drawn in the background of the CLabel. 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:
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});
| |
| setBackground | back to summary |
|---|---|
| public void setBackground(Color[] colors, int[] percents, boolean vertical) Specify a gradient of colours to be drawn in the background of the CLabel. For example, to draw a gradient that varies from dark blue to white in the vertical, direction use the following call to setBackground:
clabel.setBackground(new Color[]{display.getSystemColor(SWT.COLOR_DARK_BLUE),
display.getSystemColor(SWT.COLOR_WHITE)},
new int[] {100}, true);
| |
| setBackground | back to summary |
|---|---|
| public void setBackground(Image image) Set the image to be drawn in the background of the label.
| |
| setBottomMargin | back to summary |
|---|---|
| public void setBottomMargin(int bottomMargin) Set the label's bottom margin, in points.
| |
| setFont | back to summary |
|---|---|
| public void setFont(Font font) Overrides org. Doc from org. 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. | |
| setImage | back to summary |
|---|---|
| public void setImage(Image image) Set the label's Image.
The value
| |
| setLeftMargin | back to summary |
|---|---|
| public void setLeftMargin(int leftMargin) Set the label's horizontal left margin, in points.
| |
| setMargins | back to summary |
|---|---|
| public void setMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin) Set the label's margins, in points.
| |
| setRightMargin | back to summary |
|---|---|
| public void setRightMargin(int rightMargin) Set the label's right margin, in points.
| |
| setText | back to summary |
|---|---|
| public void setText(String text) Set the label's text.
The value Mnemonics are indicated by an '&' that causes the next character to be the mnemonic. When the user presses a key sequence that matches the mnemonic, focus is assigned to the control that follows the label. On most platforms, the mnemonic appears underlined but may be emphasised in a platform specific manner. The mnemonic indicator character '&' can be escaped by doubling it in the string, causing a single '&' to be displayed. Note If control characters like '\n', '\t' etc. are used in the string, then the behavior is platform dependent.
| |
| setToolTipText | back to summary |
|---|---|
| public void setToolTipText(String string) Overrides org. Doc from org. Sets the receiver's tool tip text to the argument, which may be null indicating that the default tool tip for the control will be shown. For a control that has a default tool tip, such as the Tree control on Windows, setting the tool tip text to an empty string replaces the default, causing no tool tip text to be shown. The mnemonic indicator (character '&') is not displayed in a tool tip. To display a single '&' in the tool tip, the character '&' can be escaped by doubling it in the string. Note This operation is a hint and behavior is platform specific, on Windows for CJK-style mnemonics of the form " (&C)" at the end of the tooltip text are not shown in tooltip. | |
| setTopMargin | back to summary |
|---|---|
| public void setTopMargin(int topMargin) Set the label's top margin, in points.
| |
| shortenText | back to summary |
|---|---|
| protected String shortenText(GC gc, String t, int width) Shorten the given text | |
| splitString | back to summary |
|---|---|
| private String[] splitString(String text) | |
| validateOffset | back to summary |
|---|---|
| pack-priv int validateOffset(TextLayout layout, int offset) | |