Package org.eclipse.jface.widgets
Class LabelFactory
java.lang.Object
org.eclipse.jface.widgets.AbstractWidgetFactory<F,C,Composite>
org.eclipse.jface.widgets.AbstractControlFactory<LabelFactory,Label>
org.eclipse.jface.widgets.LabelFactory
This class provides a convenient shorthand for creating and initializing
Label
. This offers several benefits over creating Label normal way:
- The same factory can be used many times to create several Label instances
- The setters on LabelFactory all return "this", allowing them to be chained
Label label = LabelFactory.newLabel(SWT.LEFT)// .text("Label:") // .layoutData(gridData) // .create(parent);
The above example creates a Label with a text and aligns it left. Finally the label is created in "parent".
LabelFactory labelFactory = LabelFactory.newLabel(SWT.LEFT); labelFactory.text("Label 1:").create(parent); labelFactory.text("Label 2:").create(parent); labelFactory.text("Label 3:").create(parent);
The above example creates three labels using the same instance of LabelFactory.
- Since:
- 3.18
-
Method Summary
Modifier and TypeMethodDescriptionalign
(int alignment) Controls how text and images will be displayed in the receiver.Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.static LabelFactory
newLabel
(int style) Creates a new LabelFactory with the given style.Sets the receiver's text.Methods inherited from class org.eclipse.jface.widgets.AbstractControlFactory
background, enabled, font, foreground, layoutData, orientation, supplyLayoutData, tooltip
Methods inherited from class org.eclipse.jface.widgets.AbstractWidgetFactory
addProperty, cast, create, data, data
-
Method Details
-
newLabel
Creates a new LabelFactory with the given style. Refer toLabel(Composite, int)
for possible styles.- Returns:
- a new LabelFactory instance
-
text
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.
- Parameters:
text
- the text- Returns:
- this
- See Also:
-
image
Sets the receiver's image to the argument, which may be null indicating that no image should be displayed.- Parameters:
image
- the image to display on the receiver (may be null)- Returns:
- this
- See Also:
-
align
Controls how text and images will be displayed in the receiver. The argument should be one ofLEFT
,RIGHT
orCENTER
. If the receiver is aSEPARATOR
label, the argument is ignored and the alignment is not changed.- Parameters:
alignment
- the alignment- Returns:
- this
- See Also:
-