Class LabelFactory


public final class LabelFactory extends AbstractControlFactory<LabelFactory,Label>
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
Example usage:
 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 Details

    • newLabel

      public static LabelFactory newLabel(int style)
      Creates a new LabelFactory with the given style. Refer to Label(Composite, int) for possible styles.
      Returns:
      a new LabelFactory instance
    • text

      public LabelFactory text(String 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

      public LabelFactory image(Image 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

      public LabelFactory align(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 - the alignment
      Returns:
      this
      See Also: