Class Expander
- All Implemented Interfaces:
Accessible,Buildable,ConstraintTarget,Proxy
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(org.gnome.gtk.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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theActivateCallbackcallback.static classExpander.Builder<B extends Expander.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.Nested classes/interfaces inherited from class org.gnome.gtk.Widget
Widget.DestroyCallback, Widget.DirectionChangedCallback, Widget.HideCallback, Widget.KeynavFailedCallback, Widget.MapCallback, Widget.MnemonicActivateCallback, Widget.MoveFocusCallback, Widget.QueryTooltipCallback, Widget.RealizeCallback, Widget.ShowCallback, Widget.StateFlagsChangedCallback, Widget.UnmapCallback, Widget.UnrealizeCallback, Widget.Widget$Impl, Widget.WidgetClassNested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClassNested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClassNested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.Accessible$Impl, Accessible.AccessibleInterfaceNested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTarget$Impl, ConstraintTarget.ConstraintTargetInterface -
Constructor Summary
ConstructorsConstructorDescriptionExpander()Creates a new Expander.Creates a new expander usinglabelas the text of the label.Expander(MemorySegment address) Create a Expander proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected ExpanderasParent()Returns this instance as if it were its parent type.static Expander.Builder<? extends Expander.Builder> builder()AExpander.Builderobject constructs aExpanderwith the specified properties.voidEmits the "activate" signal.@Nullable WidgetgetChild()Gets the child widget ofexpander.booleanQueries aGtkExpanderand returns its current state.@Nullable StringgetLabel()Fetches the text from a label widget.@Nullable WidgetRetrieves the label widget for the frame.booleanReturns whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.static @Nullable TypegetType()Get the GType of the Expander classbooleanReturns whether the label’s text is interpreted as Pango markup.booleanReturns whether an underline in the text indicates a mnemonic.onActivate(Expander.ActivateCallback handler) Activates theGtkExpander.voidSets the child widget ofexpander.voidsetExpanded(boolean expanded) Sets the state of the expander.voidSets the text of the label of the expander tolabel.voidsetLabelWidget(@Nullable Widget labelWidget) Set the label widget for the expander.voidsetResizeToplevel(boolean resizeToplevel) Sets whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.voidsetUseMarkup(boolean useMarkup) Sets whether the text of the label contains Pango markup.voidsetUseUnderline(boolean useUnderline) If true, an underline in the text indicates a mnemonic.static ExpanderwithMnemonic(@Nullable String label) Creates a new expander usinglabelas the text of the label.Methods inherited from class org.gnome.gtk.Widget
actionSetEnabled, activateActionIfExists, activateDefault, activateWidget, addController, addCssClass, addMnemonicLabel, addTickCallback, allocate, childFocus, computeBounds, computeExpand, computeExpand, computePoint, computeTransform, contains, createPangoContext, createPangoLayout, cssChanged, directionChanged, disposeTemplate, dragCheckThreshold, emitDestroy, emitDirectionChanged, emitHide, emitKeynavFailed, emitMap, emitMnemonicActivate, emitMoveFocus, emitQueryTooltip, emitRealize, emitShow, emitStateFlagsChanged, emitUnmap, emitUnrealize, errorBell, focus, getAllocatedBaseline, getAllocatedHeight, getAllocatedWidth, getAllocation, getAncestor, getBaseline, getCanFocus, getCanTarget, getChildVisible, getClipboard, getColor, getCssClasses, getCssName, getCursor, getDefaultDirection, getDirection, getDisplay, getFirstChild, getFocusable, getFocusChild, getFocusOnClick, getFontMap, getFontOptions, getFrameClock, getHalign, getHasTooltip, getHeight, getHexpand, getHexpandSet, getLastChild, getLayoutManager, getLimitEvents, getMapped, getMarginBottom, getMarginEnd, getMarginStart, getMarginTop, getMemoryLayout, getName, getNative, getNextSibling, getOpacity, getOverflow, getPangoContext, getParent, getPreferredSize, getPrevSibling, getPrimaryClipboard, getRealized, getReceivesDefault, getRequestMode, getRoot, getScaleFactor, getSensitive, getSettings, getSize, getSizeRequest, getStateFlags, getStyleContext, getTemplateChild, getTooltipMarkup, getTooltipText, getValign, getVexpand, getVexpandSet, getVisible, getWidth, grabFocus, hasCssClass, hasDefault, hasFocus, hasVisibleFocus, hide, inDestruction, initTemplate, insertActionGroup, insertAfter, insertBefore, isAncestor, isDrawable, isFocus, isSensitive, isVisible, keynavFailed, listMnemonicLabels, map, measure, mnemonicActivate, moveFocus, observeChildren, observeControllers, onDestroy, onDirectionChanged, onHide, onKeynavFailed, onMap, onMnemonicActivate, onMoveFocus, onQueryTooltip, onRealize, onShow, onStateFlagsChanged, onUnmap, onUnrealize, pick, pick, queryTooltip, queueAllocate, queueDraw, queueResize, realize, removeController, removeCssClass, removeMnemonicLabel, removeTickCallback, root, setCanFocus, setCanTarget, setChildVisible, setCssClasses, setCursor, setCursorFromName, setDefaultDirection, setDirection, setFocusable, setFocusChild, setFocusOnClick, setFontMap, setFontOptions, setHalign, setHasTooltip, setHexpand, setHexpandSet, setLayoutManager, setLimitEvents, setMarginBottom, setMarginEnd, setMarginStart, setMarginTop, setName, setOpacity, setOverflow, setParent, setReceivesDefault, setSensitive, setSizeRequest, setStateFlags, setStateFlags, setTooltipMarkup, setTooltipText, setValign, setVexpand, setVexpandSet, setVisible, shouldLayout, show, sizeAllocate, sizeAllocate, snapshot, snapshotChild, stateFlagsChanged, systemSettingChanged, translateCoordinates, triggerTooltipQuery, unmap, unparent, unrealize, unroot, unsetStateFlags, unsetStateFlagsMethods inherited from class org.gnome.gobject.GObject
addToggleRef, addWeakPointer, bindProperty, bindProperty, bindProperty, bindPropertyFull, bindPropertyFull, bindPropertyWithClosures, bindPropertyWithClosures, compatControl, connect, connect, connect, constructed, disconnect, dispatchPropertiesChanged, dispose, dupData, dupQdata, emit, emitNotify, finalize_, forceFloating, freezeNotify, get, getData, getProperty, getProperty, getProperty, getQdata, getv, interfaceFindProperty, interfaceInstallProperty, interfaceListProperties, isFloating, newInstance, newInstance, newv, notify, notify, notifyByPspec, onNotify, ref, refSink, removeToggleRef, removeWeakPointer, replaceData, replaceQdata, runDispose, set, setData, setDataFull, setProperty, setProperty, setProperty, setQdata, setQdataFull, setv, stealData, stealQdata, takeRef, thawNotify, unref, watchClosure, weakRef, weakUnref, withPropertiesMethods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, cast, getPrivate, readGClass, writeGClassMethods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updatePlatformState, updateProperty, updateRelation, updateStateMethods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
Expander
Create a Expander proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
Expander
Creates a new expander usinglabelas the text of the label.- Parameters:
label- the text of the label
-
Expander
public Expander()Creates a new Expander.
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuperkeyword, but will set the native typeclass function pointers to the parent type. When overriding a native virtual method in Java, "chaining up" withsuper.methodName()doesn't work, because it invokes the overridden function pointer again. To chain up, callasParent().methodName(). This will call the native function pointer of this virtual method in the typeclass of the parent type. -
withMnemonic
Creates a new expander usinglabelas the text of the label.If characters in
labelare 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
GtkExpanderwidget.
-
getChild
Gets the child widget ofexpander.- Returns:
- the child widget of this Expander
-
getExpanded
public boolean getExpanded()Queries aGtkExpanderand returns its current state.Returns
trueif the child widget is revealed.- Returns:
- the current state of the expander
-
getLabel
Fetches the text from a label widget.This is including any embedded underlines indicating mnemonics and Pango markup, as set by
setLabel(java.lang.String). If the label text has not been set the return value will benull. 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
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:
trueif the label’s text will be parsed for markup
-
getUseUnderline
public boolean getUseUnderline()Returns whether an underline in the text indicates a mnemonic.- Returns:
trueif an embedded underline in the expander label indicates the mnemonic accelerator keys
-
setChild
Sets the child widget ofexpander.- 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, andfalseif you want the child widget to be hidden.- Parameters:
expanded- whether the child widget is revealed
-
setLabel
Sets the text of the label of the expander tolabel.This will also clear any previously set labels.
- Parameters:
label- a string
-
setLabelWidget
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-trueif 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-trueif underlines in the text indicate mnemonics
-
onActivate
Activates theGtkExpander.- 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. SeeonActivate(org.gnome.gtk.Expander.ActivateCallback). -
builder
AExpander.Builderobject constructs aExpanderwith the specified properties. Use the variousset...()methods to set properties, and finish construction withExpander.Builder.build().- Returns:
- the builder object
-