Top Description Fields Constructors Methods
org.eclipse.swt.widgets

public Class Label

extends Control
Class Inheritance
Imports
org.eclipse.swt.*, org.eclipse.swt.accessibility.*, org.eclipse.swt.graphics.*, org.eclipse.swt.internal.*, org.eclipse.swt.internal.gtk.*, org.eclipse.swt.internal.gtk3.*, org.eclipse.swt.internal.gtk4.*

Instances of this class represent a non-selectable user interface object that displays a string or image. When SEPARATOR is specified, displays a single vertical or horizontal line.

Shadow styles are hints and may not be honored by the platform. To create a separator label with the default shadow style for the platform, do not specify a shadow style.

Styles:
SEPARATOR, HORIZONTAL, VERTICAL
SHADOW_IN, SHADOW_OUT, SHADOW_NONE
CENTER, LEFT, RIGHT, WRAP
Events:
(none)

Note

Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified. SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified. Only one of CENTER, LEFT and RIGHT may be specified.

Important Note

This class is not intended to be subclassed.

See Also
Label snippets, SWT Example: ControlExample, Sample code and further information

Field Summary

Modifier and TypeField and Description
pack-priv long
pack-priv long
pack-priv Image
pack-priv long
pack-priv long
pack-priv String
Inherited from org.eclipse.swt.widgets.Control:
accessibleautoScalebackgroundAlphabackgroundImagecachedNoBackgroundcheckScaleFactorcssBackgroundcssForegroundcursorDISABLE_EMOJIdragDetectionQueuedragGesturedrawCountdrawRegionenableWindoweventRegionfirstFixedHandlefixedHandlefontgestureBegingestureEndgestureRotationgestureSwipegestureZoomkeyControllerlabelRelationlastInputlayoutDatamenumouseDownpanGestureparentproviderredrawWindowregionregionHandlerotateGesturetoolTipTextzoomGesture

Constructor Summary

AccessConstructor and Description
public
Label(Composite
a composite control which will be the parent of the new instance (cannot be null)
parent
,
int
the style of control to construct
style
)

Constructs a new instance of this class given its parent and a style value describing its behavior and appearance.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
pack-priv static int
checkStyle(int style)

pack-priv Point
computeNativeSize(long h, int wHint, int hHint, boolean changed)

Overrides org.eclipse.swt.widgets.Control.computeNativeSize.

pack-priv Point
computeSizeInPixels(int wHint, int hHint, boolean changed)

Overrides org.eclipse.swt.widgets.Control.computeSizeInPixels.

pack-priv void
pack-priv void
pack-priv long
pack-priv void
pack-priv long
dpiChanged(long object, long arg0)

Overrides org.eclipse.swt.widgets.Widget.dpiChanged.

pack-priv long
public int

Returns:

the alignment
getAlignment
()

Returns a value which describes the position of the text or image in the receiver.

pack-priv int
public Image

Returns:

the receiver's image
getImage
()

Returns the receiver's image if it has one, or null if it does not.

pack-priv String
public String

Returns:

the receiver's text
getText
()

Returns the receiver's text, which will be an empty string if it has never been set or if the receiver is a SEPARATOR label.

private void
gtk_label_set_align(float xalign, float yalign)

pack-priv void
pack-priv boolean
pack-priv boolean
pack-priv boolean
pack-priv void
pack-priv void
pack-priv void
pack-priv void
public void
setAlignment(int
the new alignment
alignment
)

Controls how text and images will be displayed in the receiver.

pack-priv void
pack-priv int
setBounds(int x, int y, int width, int height, boolean move, boolean resize)

Overrides org.eclipse.swt.widgets.Control.setBounds.

pack-priv void
pack-priv void
public void
setImage(Image
the image to display on the receiver (may be null)
image
)

Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.

pack-priv void
public void
setText(String
the new text
string
)

Sets the receiver's text.

pack-priv void
pack-priv void
pack-priv long
windowProc(long handle, long arg0, long user_data)

Overrides org.eclipse.swt.widgets.Control.windowProc.

Inherited from org.eclipse.swt.widgets.Control:
_getAccessible_getShelladdControlListeneraddDragDetectListeneraddFocusListeneraddGestureListeneraddHelpListeneraddKeyListeneraddMenuDetectListeneraddMouseListeneraddMouseMoveListeneraddMouseTrackListeneraddMouseWheelListeneraddPaintListeneraddTouchListeneraddTraverseListeneradjustChildClippingcairoClipRegioncairoCopyRegioncairoDisposeRegioncheckBackgroundcheckBordercheckBufferedcheckMirroredcheckSubwindowcleanupEnableWindowcomputeSizecomputeSizecomputeSizeInPixelscomputeTabGroupcomputeTabListcomputeTabRootcontainedInRegiondefaultBackgrounddefaultFontdestroyWidgetdragDetectdragDetectdragDetectdragDetectdrawBackgrounddrawGripperdrawWidgetenableWidgetenterExitHandleeventSurfaceeventWindowfilterKeyfindBackgroundControlfindMenusfixChildrenfixFocusfixGdkEventTypeValuesfixModalfixParentGdkResourcefixStylefixStyleflushQueueOnDndfocusHandlefontHandleforceFocusforceFocusforceResizegestureBeginProcgestureEndProcgestureHandlegetAccessiblegetBackgroundgetBackgroundGdkRGBAgetBackgroundImagegetBaseGdkRGBAgetBgGdkRGBAgetBorderWidthgetBoundsgetBoundsInPixelsgetClientWidthgetContextBackgroundGdkRGBAgetContextColorGdkRGBAgetControlgetControlOrigingetCursorgetDragDetectgetEnabledgetFontgetFontDescriptiongetForegroundgetForegroundGdkRGBAgetIMCaretPosgetLayoutDatagetLocationgetLocationInPixelsgetMenugetMonitorgetOrientationgetParentgetPathgetRegiongetShellgetSizegetSizeInPixelsgetSurfaceOrigingetTextDirectiongetThicknessgetToolTipTextgetTouchEnabledgetVisiblegetWindowOrigingtk3_show_helpgtk4_drawgtk4_enter_eventgtk4_focus_enter_eventgtk4_focus_leave_eventgtk4_focus_window_eventgtk4_key_press_eventgtk4_key_release_eventgtk4_leave_eventgtk4_motion_eventgtk4_scroll_eventgtk_button_press_eventgtk_button_press_eventgtk_button_release_eventgtk_commitgtk_css_provider_load_from_cssgtk_drawgtk_enter_notify_eventgtk_event_aftergtk_focusgtk_focus_in_eventgtk_focus_out_eventgtk_gesture_press_eventgtk_gesture_release_eventgtk_key_press_eventgtk_key_release_eventgtk_label_set_aligngtk_leave_notify_eventgtk_mnemonic_activategtk_motion_notify_eventgtk_popup_menugtk_preedit_changedgtk_realizegtk_scroll_eventgtk_style_context_get_bordergtk_style_context_get_paddinggtk_style_updatedgtk_unrealizegtk_widget_reparentgtk_widget_set_alignhasFocushooksPainthoverProcimHandleinternal_dispose_GCinternal_new_GCisActiveisAutoScalableisEnabledisFocusAncestorisFocusControlisFocusHandleisReparentableisShowingisTabGroupisTabItemisVisiblemagnifyProcmarkLayoutmenuShellmoveAbovemoveBelowmoveChildrenmoveHandlemustBeVisibleOnInitBoundspackpackpaintHandlepaintSurfacepaintWindowprintprintWidgetprintWindowredrawredrawredrawredrawChildrenredrawInPixelsredrawWidgetreleasereleaseParentremoveControlListenerremoveDragDetectListenerremoveFocusListenerremoveGestureListenerremoveHelpListenerremoveKeyListenerremoveMenuDetectListenerremoveMouseListenerremoveMouseMoveListenerremoveMouseTrackListenerremoveMouseWheelListenerremovePaintListenerremoveRelationremoveTouchListenerremoveTraverseListenerrequestLayoutresizeCalculationsGTK3restackWindowrotateProcsendDragEventsendFocusEventsendGestureEventsendGestureEventsendGestureEventsendHelpEventsendLeaveNotifysendMouseEventsendMouseEventsetBackgroundsetBackgroundsetBackgroundGdkRGBAsetBackgroundGdkRGBAsetBackgroundGdkRGBAsetBackgroundImagesetBackgroundSurfacesetBoundssetBoundssetBoundsInPixelssetBoundsInPixelssetCapturesetCursorsetCursorsetDragDetectsetEnabledsetFocussetFontsetForegroundsetForegroundGdkRGBAsetInitialBoundssetLayoutDatasetLocationsetLocationsetLocationInPixelssetLocationInPixelssetMenusetOrientationsetParentsetParentBackgroundsetParentGdkResourcesetRadioSelectionsetRedrawsetRegionsetRelationssetSizesetSizesetSizeInPixelssetSizeInPixelssetTabItemFocussetTextDirectionsetToolTipTextsetToolTipTextsetTouchEnabledsetVisiblesetZOrdersetZOrdershowMenushowMenusortswipeProctoControltoControltoDisplaytoDisplaytoDisplayInPixelstoDisplayInPixelstopHandletranslateMnemonictranslateMnemonictranslateTraversaltraversalCodetraversetraversetraversetraversetraversetraverseEscapetraverseGrouptraverseItemtraverseMnemonictraversePagetraverseReturnupdateupdateupdateBackgroundModeupdateLayoutwantDragDropDetection

Field Detail

boxHandleback to summary
pack-priv long boxHandle
frameHandleback to summary
pack-priv long frameHandle
imageback to summary
pack-priv Image image
imageHandleback to summary
pack-priv long imageHandle
labelHandleback to summary
pack-priv long labelHandle
textback to summary
pack-priv String text

Constructor Detail

Labelback to summary
public Label(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 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.

Parameters
parent:Composite

a composite control which will be the parent of the new instance (cannot be null)

style:int

the style of control to construct

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the parent is null
SWTException:
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent
  • ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass
See Also
SWT#SEPARATOR, SWT#HORIZONTAL, SWT#VERTICAL, SWT#SHADOW_IN, SWT#SHADOW_OUT, SWT#SHADOW_NONE, SWT#CENTER, SWT#LEFT, SWT#RIGHT, SWT#WRAP, Widget#checkSubclass, Widget#getStyle

Method Detail

addRelationback to summary
pack-priv void addRelation(Control control)

Overrides org.eclipse.swt.widgets.Control.addRelation.

Annotations
@Override
checkStyleback to summary
pack-priv static int checkStyle(int style)
computeNativeSizeback to summary
pack-priv Point computeNativeSize(long h, int wHint, int hHint, boolean changed)

Overrides org.eclipse.swt.widgets.Control.computeNativeSize.

Annotations
@Override
computeSizeInPixelsback to summary
pack-priv Point computeSizeInPixels(int wHint, int hHint, boolean changed)

Overrides org.eclipse.swt.widgets.Control.computeSizeInPixels.

Annotations
@Override
createHandleback to summary
pack-priv void createHandle(int index)

Overrides org.eclipse.swt.widgets.Widget.createHandle.

Annotations
@Override
createWidgetback to summary
pack-priv void createWidget(int index)

Overrides org.eclipse.swt.widgets.Control.createWidget.

Annotations
@Override
cssHandleback to summary
pack-priv long cssHandle()

Overrides org.eclipse.swt.widgets.Widget.cssHandle.

Annotations
@Override
deregisterback to summary
pack-priv void deregister()

Overrides org.eclipse.swt.widgets.Control.deregister.

Annotations
@Override
dpiChangedback to summary
pack-priv long dpiChanged(long object, long arg0)

Overrides org.eclipse.swt.widgets.Widget.dpiChanged.

Annotations
@Override
eventHandleback to summary
pack-priv long eventHandle()

Overrides org.eclipse.swt.widgets.Control.eventHandle.

Annotations
@Override
getAlignmentback to summary
public int getAlignment()

Returns a value which describes the position of the text or image in the receiver. The value will be one of LEFT, RIGHT or CENTER unless the receiver is a SEPARATOR label, in which case, NONE is returned.

Returns:int

the alignment

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
getBorderWidthInPixelsback to summary
pack-priv int getBorderWidthInPixels()

Overrides org.eclipse.swt.widgets.Control.getBorderWidthInPixels.

Annotations
@Override
getImageback to summary
public Image getImage()

Returns the receiver's image if it has one, or null if it does not.

Returns:Image

the receiver's image

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
getNameTextback to summary
pack-priv String getNameText()

Overrides org.eclipse.swt.widgets.Widget.getNameText.

Annotations
@Override
getTextback to summary
public String getText()

Returns the receiver's text, which will be an empty string if it has never been set or if the receiver is a SEPARATOR label.

Returns:String

the receiver's text

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
gtk_label_set_alignback to summary
private void gtk_label_set_align(float xalign, float yalign)
hookEventsback to summary
pack-priv void hookEvents()

Overrides org.eclipse.swt.widgets.Control.hookEvents.

Annotations
@Override
isDescribedByLabelback to summary
pack-priv boolean isDescribedByLabel()

Overrides org.eclipse.swt.widgets.Control.isDescribedByLabel.

Annotations
@Override
mnemonicHitback to summary
pack-priv boolean mnemonicHit(char key)

Overrides org.eclipse.swt.widgets.Control.mnemonicHit.

Annotations
@Override
mnemonicMatchback to summary
pack-priv boolean mnemonicMatch(char key)

Overrides org.eclipse.swt.widgets.Control.mnemonicMatch.

Annotations
@Override
registerback to summary
pack-priv void register()

Overrides org.eclipse.swt.widgets.Control.register.

Annotations
@Override
releaseHandleback to summary
pack-priv void releaseHandle()

Overrides org.eclipse.swt.widgets.Control.releaseHandle.

Annotations
@Override
releaseWidgetback to summary
pack-priv void releaseWidget()

Overrides org.eclipse.swt.widgets.Control.releaseWidget.

Annotations
@Override
resizeHandleback to summary
pack-priv void resizeHandle(int width, int height)

Overrides org.eclipse.swt.widgets.Control.resizeHandle.

Annotations
@Override
setAlignmentback to summary
public void setAlignment(int alignment)

Controls how text and images will be displayed in the receiver. The argument should be one of LEFT, RIGHT or CENTER. If the receiver is a SEPARATOR label, the argument is ignored and the alignment is not changed.

Parameters
alignment:int

the new alignment

Exceptions
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
setAlignmentback to summary
pack-priv void setAlignment()
setBoundsback to summary
pack-priv int setBounds(int x, int y, int width, int height, boolean move, boolean resize)

Overrides org.eclipse.swt.widgets.Control.setBounds.

Annotations
@Override
setFontDescriptionback to summary
pack-priv void setFontDescription(long font)

Overrides org.eclipse.swt.widgets.Control.setFontDescription.

Annotations
@Override
setForegroundGdkRGBAback to summary
pack-priv void setForegroundGdkRGBA(GdkRGBA rgba)

Overrides org.eclipse.swt.widgets.Control.setForegroundGdkRGBA.

Annotations
@Override
setImageback to summary
public void setImage(Image image)

Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.

Parameters
image:Image

the image to display on the receiver (may be null)

Exceptions
IllegalArgumentException:
  • ERROR_INVALID_ARGUMENT - if the image has been disposed
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
setOrientationback to summary
pack-priv void setOrientation(boolean create)

Overrides org.eclipse.swt.widgets.Control.setOrientation.

Annotations
@Override
setTextback to summary
public void setText(String string)

Sets the receiver's text.

This method sets the widget label. The label may include the mnemonic character and line delimiters.

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.

Parameters
string:String

the new text

Exceptions
IllegalArgumentException:
  • ERROR_NULL_ARGUMENT - if the text is null
SWTException:
  • ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  • ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
setWidgetBackgroundback to summary
pack-priv void setWidgetBackground()

Overrides org.eclipse.swt.widgets.Control.setWidgetBackground.

Annotations
@Override
showWidgetback to summary
pack-priv void showWidget()

Overrides org.eclipse.swt.widgets.Control.showWidget.

Annotations
@Override
windowProcback to summary
pack-priv long windowProc(long handle, long arg0, long user_data)

Overrides org.eclipse.swt.widgets.Control.windowProc.

Annotations
@Override