Class CLabel
- java.lang.Object
-
public class CLabel extends Canvas
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
- Styles:
- LEFT, RIGHT, CENTER, SHADOW_IN, SHADOW_OUT, SHADOW_NONE
- Events:
IMPORTANT: This class is not intended to be subclassed.
- Since:
- 1.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Point
computeSize(int wHint, int hHint, boolean changed)
Returns the preferred size of the receiver.<T> T
getAdapter(java.lang.Class<T> adapter)
Implementation of theAdaptable
interface.int
getAlignment()
Returns the alignment.int
getBottomMargin()
Return the CLabel's bottom margin.Image
getImage()
Return the CLabel's image ornull
.int
getLeftMargin()
Return the CLabel's left margin.int
getRightMargin()
Return the CLabel's right margin.int
getStyle()
Returns the receiver's style information.java.lang.String
getText()
Return the Label's text.java.lang.String
getToolTipText()
Returns the receiver's tool tip text, or null if it has not been set.int
getTopMargin()
Return the CLabel's top margin.void
setAlignment(int align)
Set the alignment of the CLabel.void
setBackground(Color 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.void
setBackground(Color[] colors, int[] percents)
Specify a gradient of colours to be drawn in the background of the CLabel.void
setBackground(Color[] colors, int[] percents, boolean vertical)
Specify a gradient of colours to be drawn in the background of the CLabel.void
setBackground(Image image)
Set the image to be drawn in the background of the label.void
setBottomMargin(int bottomMargin)
Set the label's bottom margin, in pixels.void
setData(java.lang.String key, java.lang.Object value)
Sets the application defined property of the receiver with the specified name to the given value.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
setLeftMargin(int leftMargin)
Set the label's horizontal left margin, in pixels.void
setMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin)
Set the label's margins, in pixels.void
setRightMargin(int rightMargin)
Set the label's right margin, in pixels.void
setText(java.lang.String text)
Set the label's text.void
setToolTipText(java.lang.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.void
setTopMargin(int topMargin)
Set the label's top margin, in pixels.-
Methods inherited from class org.eclipse.swt.widgets.Canvas
addPaintListener, removePaintListener
-
Methods inherited from class org.eclipse.swt.widgets.Composite
changed, getBackgroundMode, getChildren, getLayout, getLayoutDeferred, getTabList, isLayoutDeferred, layout, layout, layout, layout, layout, setBackgroundMode, setFocus, setLayout, setLayoutDeferred, setTabList
-
Methods inherited from class org.eclipse.swt.widgets.Scrollable
computeTrim, getClientArea, getHorizontalBar, getVerticalBar
-
Methods inherited from class org.eclipse.swt.widgets.Control
addControlListener, addDragDetectListener, addFocusListener, addGestureListener, addHelpListener, addKeyListener, addMenuDetectListener, addMouseListener, addTouchListener, addTraverseListener, computeSize, forceFocus, getAccessible, getBackground, getBackgroundImage, getBorderWidth, getBounds, getCursor, getEnabled, getFont, getForeground, getLayoutData, getLocation, getMenu, getMonitor, getOrientation, getParent, getShell, getSize, getTouchEnabled, getVisible, isEnabled, isFocusControl, isReparentable, isVisible, moveAbove, moveBelow, pack, pack, redraw, redraw, removeControlListener, removeDragDetectListener, removeFocusListener, removeGestureListener, removeHelpListener, removeKeyListener, removeMenuDetectListener, removeMouseListener, removeTouchListener, removeTraverseListener, requestLayout, setBackgroundImage, setBounds, setBounds, setCursor, setEnabled, setForeground, setLayoutData, setLocation, setLocation, setMenu, setOrientation, setParent, setRedraw, setSize, setSize, setTouchEnabled, setVisible, toControl, toControl, toDisplay, toDisplay, update
-
Methods inherited from class org.eclipse.swt.widgets.Widget
addDisposeListener, addListener, checkSubclass, checkWidget, dispose, getData, getData, getDisplay, getListeners, isDisposed, isListening, notifyListeners, removeDisposeListener, removeListener, removeListener, reskin, setData, toString
-
-
-
-
Constructor Detail
-
CLabel
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
SWT
which is applicable to instances of this class, or must be built by bitwise OR'ing together (that is, using theint
"|" operator) two or more of thoseSWT
style constants. The class description lists the style constants that are applicable to the class. Style bits are also inherited from superclasses.- Parameters:
parent
- a widget which will be the parent of the new instance (cannot be null)style
- the style of widget to construct- Throws:
java.lang.IllegalArgumentException
-- ERROR_NULL_ARGUMENT - if the parent is null
SWTException
-- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
- See Also:
SWT.LEFT
,SWT.RIGHT
,SWT.CENTER
,SWT.SHADOW_IN
,SWT.SHADOW_OUT
,SWT.SHADOW_NONE
,getStyle()
-
-
Method Detail
-
computeSize
public Point computeSize(int wHint, int hHint, boolean changed)
Description copied from class:Control
Returns the preferred size 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
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 befalse
, so layout manager caches can be retained.- Overrides:
computeSize
in classComposite
- Parameters:
wHint
- the width hint (can beSWT.DEFAULT
)hHint
- the height hint (can beSWT.DEFAULT
)changed
-true
if the control's contents have changed, andfalse
otherwise- Returns:
- the preferred size of the control.
- See Also:
Layout
,Control.getBorderWidth()
,Control.getBounds()
,Control.getSize()
,Control.pack(boolean)
, "computeTrim, getClientArea for controls that implement them"
-
getAlignment
public int getAlignment()
Returns the alignment. The alignment style (LEFT, CENTER or RIGHT) is returned.- Returns:
- SWT.LEFT, SWT.RIGHT or SWT.CENTER
-
getImage
public Image getImage()
Return the CLabel's image ornull
.- Returns:
- the image of the label or null
-
getStyle
public int getStyle()
Description copied from class:Widget
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
SWT.H_SCROLL
andSWT.V_SCROLL
bits set.
-
getText
public java.lang.String getText()
Return the Label's text.- Returns:
- the text of the label or null
-
getToolTipText
public java.lang.String getToolTipText()
Description copied from class:Control
Returns the receiver's tool tip text, or null if it has not been set.- Overrides:
getToolTipText
in classControl
- Returns:
- the receiver's tool tip text
-
setAlignment
public 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.- Parameters:
align
- the alignment style of LEFT, RIGHT or CENTER- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- ERROR_INVALID_ARGUMENT - if the value of align is not one of SWT.LEFT, SWT.RIGHT or SWT.CENTER
-
setBackground
public void setBackground(Color color)
Description copied from class:Control
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.- Overrides:
setBackground
in classControl
- Parameters:
color
- the new color (or null)
-
setBackground
public void setBackground(Image image)
Set the image to be drawn in the background of the label.- Parameters:
image
- the image to be drawn in the background- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setBackground
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});
- Parameters:
colors
- an array of Color that specifies the colors to appear in the gradient in order of appearance from left to right; The valuenull
clears the background gradient; the valuenull
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.- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- ERROR_INVALID_ARGUMENT - if the values of colors and percents are not consistent
- Since:
- 1.4
-
setBackground
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);
- Parameters:
colors
- an array of Color that specifies the colors to appear in the gradient in order of appearance from left/top to right/bottom; The valuenull
clears the background gradient; the valuenull
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/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.vertical
- indicate the direction of the gradient. True is vertical and false is horizontal.- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- ERROR_INVALID_ARGUMENT - if the values of colors and percents are not consistent
- Since:
- 1.4
-
setFont
public void setFont(Font font)
Description copied from class:Control
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
public void setImage(Image image)
Set the label's Image. The valuenull
clears it.- Parameters:
image
- the image to be displayed in the label or null- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setText
public void setText(java.lang.String text)
Set the label's text. The valuenull
clears it.- Parameters:
text
- the text to be displayed in the label or null- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
-
setToolTipText
public void setToolTipText(java.lang.String string)
Description copied from class:Control
Sets the receiver's tool tip text to the argument, which may be null indicating that no tool tip text should be shown.- Overrides:
setToolTipText
in classControl
- Parameters:
string
- the new tool tip text (or null)
-
setMargins
public void setMargins(int leftMargin, int topMargin, int rightMargin, int bottomMargin)
Set the label's margins, in pixels.- Parameters:
leftMargin
- the left margin.topMargin
- the top margin.rightMargin
- the right margin.bottomMargin
- the bottom margin.- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
setLeftMargin
public void setLeftMargin(int leftMargin)
Set the label's horizontal left margin, in pixels.- Parameters:
leftMargin
- the left margin of the label, which must be equal to or greater than zero- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
getLeftMargin
public int getLeftMargin()
Return the CLabel's left margin.- Returns:
- the left margin of the label
- Since:
- 1.3
-
setTopMargin
public void setTopMargin(int topMargin)
Set the label's top margin, in pixels.- Parameters:
topMargin
- the top margin of the label, which must be equal to or greater than zero- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
getTopMargin
public int getTopMargin()
Return the CLabel's top margin.- Returns:
- the top margin of the label
- Since:
- 1.3
-
setRightMargin
public void setRightMargin(int rightMargin)
Set the label's right margin, in pixels.- Parameters:
rightMargin
- the right margin of the label, which must be equal to or greater than zero- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
getRightMargin
public int getRightMargin()
Return the CLabel's right margin.- Returns:
- the right margin of the label
- Since:
- 1.3
-
setBottomMargin
public void setBottomMargin(int bottomMargin)
Set the label's bottom margin, in pixels.- Parameters:
bottomMargin
- the bottom margin of the label, which must be equal to or greater than zero- Throws:
SWTException
-- ERROR_WIDGET_DISPOSED - if the receiver has been disposed
- ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
- Since:
- 1.3
-
getBottomMargin
public int getBottomMargin()
Return the CLabel's bottom margin.- Returns:
- the bottom margin of the label
- Since:
- 1.3
-
setData
public void setData(java.lang.String key, java.lang.Object value)
Description copied from class:Widget
Sets the application defined property of the receiver with the specified name to the given value.Applications may associate arbitrary objects with the receiver in this fashion. If the objects stored in the properties need to be notified when the widget is disposed of, it is the application's responsibility to hook the Dispose event on the widget and do so.
- Overrides:
setData
in classControl
- Parameters:
key
- the name of the propertyvalue
- the new value for the property- See Also:
Widget.getData(String)
-
getAdapter
public <T> T getAdapter(java.lang.Class<T> adapter)
Description copied from class:Widget
Implementation of theAdaptable
interface.IMPORTANT: This method is not part of the RWT public API. It is marked public only so that it can be shared within the packages provided by RWT. It should never be accessed from application code.
- Specified by:
getAdapter
in interfaceAdaptable
- Overrides:
getAdapter
in classCanvas
- Parameters:
adapter
- the lookup class- Returns:
- an object that can be cast to the given class or
null
if there is no adapter associated with the given class.
-
-