Class Label.Builder<B extends Label.Builder<B>>

Type Parameters:
B - the type of the Builder that is returned
All Implemented Interfaces:
Accessible.Builder<B>, BuilderInterface
Enclosing class:
Label

public static class Label.Builder<B extends Label.Builder<B>> extends Widget.Builder<B> implements Accessible.Builder<B>
Inner class implementing a builder pattern to construct a GObject with properties.
  • Constructor Details

    • Builder

      protected Builder()
      Default constructor for a Builder object.
  • Method Details

    • build

      public Label build()
      Finish building the Label object. This will call GObject.withProperties(Type, String[], Value[]) to create a new GObject instance, which is then cast to Label.
      Overrides:
      build in class Widget.Builder<B extends Label.Builder<B>>
      Returns:
      a new instance of Label with the properties that were set in the Builder object.
    • setAttributes

      public B setAttributes(AttrList attributes)
      A list of style attributes to apply to the text of the label.
      Parameters:
      attributes - the value for the attributes property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setEllipsize

      public B setEllipsize(EllipsizeMode ellipsize)

      The preferred place to ellipsize the string, if the label does not have enough room to display the entire string.

      Note that setting this property to a value other than Gtk.NotebookPage:tab-expand child property is set to true.

      Other ways to set a label's width are Widget.setSizeRequest(int, int) and Label.setWidthChars(int).

      Parameters:
      ellipsize - the value for the ellipsize property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setExtraMenu

      public B setExtraMenu(MenuModel extraMenu)
      A menu model whose contents will be appended to the context menu.
      Parameters:
      extraMenu - the value for the extra-menu property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setJustify

      public B setJustify(Justification justify)

      The alignment of the lines in the text of the label, relative to each other.

      This does not affect the alignment of the label within its allocation. See Gtk.Label:xalign for that.

      Parameters:
      justify - the value for the justify property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setLabel

      public B setLabel(String label)

      The contents of the label.

      If the string contains Pango markup (see Pango#parseMarkup), you will have to set the Gtk.Label:use-markup property to true in order for the label to display the markup attributes. See also Label.setMarkup(String) for a convenience function that sets both this property and the Gtk.Label:use-markup property at the same time.

      If the string contains underlines acting as mnemonics, you will have to set the Gtk.Label:use-underline property to true in order for the label to display them.

      Parameters:
      label - the value for the label property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setLines

      public B setLines(int lines)

      The number of lines to which an ellipsized, wrapping label should display before it gets ellipsized. This both prevents the label from ellipsizing before this many lines are displayed, and limits the height request of the label to this many lines.

      ::: warning Setting this property has unintuitive and unfortunate consequences for the minimum width of the label. Specifically, if the height of the label is such that it fits a smaller number of lines than the value of this property, the label can not be ellipsized at all, which means it must be wide enough to fit all the text fully.

      This property has no effect if the label is not wrapping or ellipsized.

      Set this property to -1 if you don't want to limit the number of lines.

      Parameters:
      lines - the value for the lines property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setMaxWidthChars

      public B setMaxWidthChars(int maxWidthChars)

      The desired maximum width of the label, in characters.

      If this property is set to -1, the width will be calculated automatically.

      See the section on text layout for details of how Gtk.Label:width-chars and Gtk.Label:max-width-chars determine the width of ellipsized and wrapped labels.

      Parameters:
      maxWidthChars - the value for the max-width-chars property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setMnemonicWidget

      public B setMnemonicWidget(Widget mnemonicWidget)
      The widget to be activated when the labels mnemonic key is pressed.
      Parameters:
      mnemonicWidget - the value for the mnemonic-widget property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setNaturalWrapMode

      public B setNaturalWrapMode(NaturalWrapMode naturalWrapMode)

      Select the line wrapping for the natural size request.

      This only affects the natural size requested. For the actual wrapping used, see the Gtk.Label:wrap-mode property.

      The default is Gtk.NaturalWrapMode.inherit, which inherits the behavior of the Gtk.Label:wrap-mode property.

      Parameters:
      naturalWrapMode - the value for the natural-wrap-mode property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      4.6
    • setSelectable

      public B setSelectable(boolean selectable)
      Whether the label text can be selected with the mouse.
      Parameters:
      selectable - the value for the selectable property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setSingleLineMode

      public B setSingleLineMode(boolean singleLineMode)

      Whether the label is in single line mode.

      In single line mode, the height of the label does not depend on the actual text, it is always set to ascent + descent of the font. This can be an advantage in situations where resizing the label because of text changes would be distracting, e.g. in a statusbar.

      Parameters:
      singleLineMode - the value for the single-line-mode property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setTabs

      public B setTabs(TabArray tabs)
      Custom tabs for this label.
      Parameters:
      tabs - the value for the tabs property
      Returns:
      the Builder instance is returned, to allow method chaining
      Since:
      4.8
    • setUseMarkup

      public B setUseMarkup(boolean useMarkup)

      True if the text of the label includes Pango markup.

      See Pango#parseMarkup.

      Parameters:
      useMarkup - the value for the use-markup property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setUseUnderline

      public B setUseUnderline(boolean useUnderline)
      True if the text of the label indicates a mnemonic with an _ before the mnemonic character.
      Parameters:
      useUnderline - the value for the use-underline property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setWidthChars

      public B setWidthChars(int widthChars)

      The desired width of the label, in characters.

      If this property is set to -1, the width will be calculated automatically.

      See the section on text layout for details of how Gtk.Label:width-chars and Gtk.Label:max-width-chars determine the width of ellipsized and wrapped labels.

      Parameters:
      widthChars - the value for the width-chars property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setWrap

      public B setWrap(boolean wrap)
      True if the label text will wrap if it gets too wide.
      Parameters:
      wrap - the value for the wrap property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setWrapMode

      public B setWrapMode(WrapMode wrapMode)

      Controls how the line wrapping is done.

      This only affects the formatting if line wrapping is on (see the Gtk.Label:wrap property). The default is Pango.WrapMode.word, which means wrap on word boundaries.

      For sizing behavior, also consider the Gtk.Label:natural-wrap-mode property.

      Parameters:
      wrapMode - the value for the wrap-mode property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setXalign

      public B setXalign(float xalign)

      The horizontal alignment of the label text inside its size allocation.

      Compare this to Gtk.Widget:halign, which determines how the labels size allocation is positioned in the space available for the label.

      Parameters:
      xalign - the value for the xalign property
      Returns:
      the Builder instance is returned, to allow method chaining
    • setYalign

      public B setYalign(float yalign)

      The vertical alignment of the label text inside its size allocation.

      Compare this to Gtk.Widget:valign, which determines how the labels size allocation is positioned in the space available for the label.

      Parameters:
      yalign - the value for the yalign property
      Returns:
      the Builder instance is returned, to allow method chaining
    • onActivateCurrentLink

      public B onActivateCurrentLink(Label.ActivateCurrentLinkCallback handler)

      Gets emitted when the user activates a link in the label.

      The ::activate-current-link is a keybinding signal.

      Applications may also emit the signal with g_signal_emit_by_name() if they need to control activation of URIs programmatically.

      The default bindings for this signal are all forms of the Enter key.

      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also:
    • onActivateLink

      public B onActivateLink(Label.ActivateLinkCallback handler)

      Gets emitted to activate a URI.

      Applications may connect to it to override the default behaviour, which is to call FileLauncher.launch(Window, Cancellable, AsyncReadyCallback).

      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also:
    • onCopyClipboard

      public B onCopyClipboard(Label.CopyClipboardCallback handler)

      Gets emitted to copy the selection to the clipboard.

      The ::copy-clipboard signal is a keybinding signal.

      The default binding for this signal is Ctrl+c.

      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also:
    • onMoveCursor

      public B onMoveCursor(Label.MoveCursorCallback handler)

      Gets emitted when the user initiates a cursor movement.

      The ::move-cursor signal is a keybinding signal. If the cursor is not visible in entry, this signal causes the viewport to be moved instead.

      Applications should not connect to it, but may emit it with GObjects#signalEmitByName if they need to control the cursor programmatically.

      The default bindings for this signal come in two variants, the variant with the Shift modifier extends the selection, the variant without the Shift modifier does not. There are too many key combinations to list them all here.

      • , , , move by individual characters/lines
      • Ctrl+, etc. move by words/paragraphs
      • Home and End move to the ends of the buffer
      Parameters:
      handler - the signal handler
      Returns:
      the Builder instance is returned, to allow method chaining
      See Also: