Class ButtonContent

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

@Generated("org.javagi.JavaGI") public final class ButtonContent extends Widget implements Accessible, Buildable, ConstraintTarget

A helper widget for creating buttons.

button-content

AdwButtonContent is a box-like widget with an icon and a label.

It's intended to be used as a direct child of Button, MenuButton or SplitButton, when they need to have both an icon and a label, as follows:

<object class="GtkButton">
  <property name="child">
    <object class="AdwButtonContent">
      <property name="icon-name">document-open-symbolic</property>
      <property name="label" translatable="yes">_Open</property>
      <property name="use-underline">True</property>
    </object>
  </property>
</object>

AdwButtonContent handles style classes and connecting the mnemonic to the button automatically.

CSS nodes

buttoncontent
╰── box
    ├── image
    ╰── label

AdwButtonContent's CSS node is called buttoncontent. It contains a box subnode that serves as a container for the image and label nodes.

When inside a GtkButton or AdwSplitButton, the button will receive the .image-text-button style class. When inside a GtkMenuButton, the internal GtkButton will receive it instead.

Accessibility

AdwButtonContent uses the Gtk.AccessibleRole.group role.

  • Constructor Details

    • ButtonContent

      public ButtonContent(MemorySegment address)
      Create a ButtonContent instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • ButtonContent

      public ButtonContent()
      Create a new ButtonContent.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the ButtonContent class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected ButtonContent asParent()
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • getCanShrink

      public boolean getCanShrink()
      gets whether the button can be smaller than the natural size of its contents.
      Returns:
      whether the button can shrink
      Since:
      1.4
    • getIconName

      public String getIconName()
      Gets the name of the displayed icon.
      Returns:
      the icon name
    • getLabel

      public String getLabel()
      Gets the displayed label.
      Returns:
      the label
    • getUseUnderline

      public boolean getUseUnderline()
      Gets whether an underline in the text indicates a mnemonic.
      Returns:
      whether an underline in the text indicates a mnemonic
    • setCanShrink

      public void setCanShrink(boolean canShrink)

      Sets whether the button can be smaller than the natural size of its contents.

      If set to TRUE, the label will ellipsize.

      See Button#setCanShrink.

      Parameters:
      canShrink - whether the button can shrink
      Since:
      1.4
    • setIconName

      public void setIconName(String iconName)

      Sets the name of the displayed icon.

      If empty, the icon is not shown.

      Parameters:
      iconName - the new icon name
    • setLabel

      public void setLabel(String label)
      Sets the displayed label.
      Parameters:
      label - the new label
    • setUseUnderline

      public void setUseUnderline(boolean useUnderline)

      Sets whether an underline in the text indicates a mnemonic.

      The mnemonic can be used to activate the parent button.

      See ButtonContent:label.

      Parameters:
      useUnderline - whether an underline in the text indicates a mnemonic
    • builder

      public static ButtonContent.Builder<? extends ButtonContent.Builder> builder()
      A ButtonContent.Builder object constructs a ButtonContent with the specified properties. Use the various set...() methods to set properties, and finish construction with ButtonContent.Builder.build().
      Returns:
      the builder object