Class Expander

All Implemented Interfaces:
Accessible, Buildable, ConstraintTarget, Proxy

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

Allows the user to reveal or conceal a child widget.

An example GtkExpander

This is similar to the triangles used in a GtkTreeView.

Normally you use an expander as you would use a frame; you create the child widget and use setChild(Widget) to add it to the expander. When the expander is toggled, it will take care of showing and hiding the child automatically.

Special Usage

There are situations in which you may prefer to show and hide the expanded widget yourself, such as when you want to actually create the widget at expansion time. In this case, create a GtkExpander but do not add a child to it. The expander widget has an Gtk.Expander:expanded property which can be used to monitor its expansion state. You should watch this property with a signal connection as follows:

static void
expander_callback (GObject    *object,
                   GParamSpec *param_spec,
                   gpointer    user_data)
{
  GtkExpander *expander;

  expander = GTK_EXPANDER (object);

  if (gtk_expander_get_expanded (expander))
    {
      // Show or create widgets
    }
  else
    {
      // Hide or destroy widgets
    }
}

static void
create_expander (void)
{
  GtkWidget *expander = gtk_expander_new_with_mnemonic ("_More Options");
  g_signal_connect (expander, "notify::expanded",
                    G_CALLBACK (expander_callback), NULL);

  // ...
}

GtkExpander as GtkBuildable

An example of a UI definition fragment with GtkExpander:

<object class="GtkExpander">
  <property name="label-widget">
    <object class="GtkLabel" id="expander-label"/>
  </property>
  <property name="child">
    <object class="GtkEntry" id="expander-content"/>
  </property>
</object>

CSS nodes

expander-widget
╰── box
    ├── title
    │   ├── expander
    │   ╰── <label widget>
    ╰── <child>

GtkExpander has a main node expander-widget, and subnode box containing the title and child widget. The box subnode title contains node expander, i.e. the expand/collapse arrow; then the label widget if any. The arrow of an expander that is showing its child gets the :checked pseudoclass set on it.

Accessibility

GtkExpander uses the Gtk.AccessibleRole.button role.

  • Constructor Details

    • Expander

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

      public Expander(@Nullable String label)
      Creates a new expander using label as the text of the label.
      Parameters:
      label - the text of the label
    • Expander

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

    • getType

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

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

      protected Expander 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
    • withMnemonic

      public static Expander withMnemonic(@Nullable String label)

      Creates a new expander using label as the text of the label.

      If characters in label are preceded by an underscore, they are underlined. If you need a literal underscore character in a label, use “__” (two underscores). The first underlined character represents a keyboard accelerator called a mnemonic.

      Pressing Alt and that key activates the button.

      Parameters:
      label - the text of the label with an underscore in front of the mnemonic character
      Returns:
      a new GtkExpander widget.
    • getChild

      public @Nullable Widget getChild()
      Gets the child widget of expander.
      Returns:
      the child widget of this Expander
    • getExpanded

      public boolean getExpanded()

      Queries a GtkExpander and returns its current state.

      Returns true if the child widget is revealed.

      Returns:
      the current state of the expander
    • getLabel

      public @Nullable String getLabel()

      Fetches the text from a label widget.

      This is including any embedded underlines indicating mnemonics and Pango markup, as set by setLabel(String). If the label text has not been set the return value will be null. This will be the case if you create an empty button with gtk_button_new() to use as a container.

      Returns:
      The text of the label widget. This string is owned by the widget and must not be modified or freed.
    • getLabelWidget

      public @Nullable Widget getLabelWidget()
      Retrieves the label widget for the frame.
      Returns:
      the label widget
    • getResizeToplevel

      public boolean getResizeToplevel()
      Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.
      Returns:
      the “resize toplevel” setting.
    • getUseMarkup

      public boolean getUseMarkup()
      Returns whether the label’s text is interpreted as Pango markup.
      Returns:
      true if the label’s text will be parsed for markup
    • getUseUnderline

      public boolean getUseUnderline()
      Returns whether an underline in the text indicates a mnemonic.
      Returns:
      true if an embedded underline in the expander label indicates the mnemonic accelerator keys
    • setChild

      public void setChild(@Nullable Widget child)
      Sets the child widget of expander.
      Parameters:
      child - the child widget
    • setExpanded

      public void setExpanded(boolean expanded)

      Sets the state of the expander.

      Set to true, if you want the child widget to be revealed, and false if you want the child widget to be hidden.

      Parameters:
      expanded - whether the child widget is revealed
    • setLabel

      public void setLabel(@Nullable String label)

      Sets the text of the label of the expander to label.

      This will also clear any previously set labels.

      Parameters:
      label - a string
    • setLabelWidget

      public void setLabelWidget(@Nullable Widget labelWidget)

      Set the label widget for the expander.

      This is the widget that will appear embedded alongside the expander arrow.

      Parameters:
      labelWidget - the new label widget
    • setResizeToplevel

      public void setResizeToplevel(boolean resizeToplevel)
      Sets whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.
      Parameters:
      resizeToplevel - whether to resize the toplevel
    • setUseMarkup

      public void setUseMarkup(boolean useMarkup)
      Sets whether the text of the label contains Pango markup.
      Parameters:
      useMarkup - true if the label’s text should be parsed for markup
    • setUseUnderline

      public void setUseUnderline(boolean useUnderline)
      If true, an underline in the text indicates a mnemonic.
      Parameters:
      useUnderline - true if underlines in the text indicate mnemonics
    • onActivate

      Activates the GtkExpander.
      Parameters:
      handler - the signal handler
      Returns:
      a signal handler ID to keep track of the signal connection
      See Also:
    • emitActivate

      public void emitActivate()
      Emits the "activate" signal. See onActivate(Expander.ActivateCallback).
    • builder

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