Class Expander
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,ConstraintTarget
GtkExpander
allows the user to reveal its child by clicking
on an expander triangle.
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
The GtkExpander
implementation of the GtkBuildable
interface supports
placing a child in the label position by specifying “label” as the
“type” attribute of a <child>
element. A normal content child can be
specified without specifying a <child>
type attribute.
An example of a UI definition fragment with GtkExpander:
<object class="GtkExpander">
<child type="label">
<object class="GtkLabel" id="expander-label"/>
</child>
<child>
<object class="GtkEntry" id="expander-content"/>
</child>
</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 AccessibleRole.BUTTON
role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theActivateCallback
callback.static class
Expander.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.WidgetClass, Widget.WidgetImpl
Nested classes/interfaces inherited from class org.gnome.gobject.InitiallyUnowned
InitiallyUnowned.InitiallyUnownedClass
Nested classes/interfaces inherited from class org.gnome.gobject.GObject
GObject.NotifyCallback, GObject.ObjectClass
Nested classes/interfaces inherited from interface org.gnome.gtk.Accessible
Accessible.AccessibleImpl, Accessible.AccessibleInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.BuildableIface, Buildable.BuildableImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
-
Constructor Summary
ConstructorDescriptionExpander()
CallsExpander(java.lang.String)
with label =null
Creates a new expander usinglabel
as the text of the label.Expander
(MemorySegment address) Create a Expander proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected Expander
asParent()
Returns this instance as if it were its parent type.static Expander.Builder
<? extends Expander.Builder> builder()
AExpander.Builder
object constructs aExpander
with the specified properties.void
Emits the "activate" signal.getChild()
Gets the child widget of this Expander.boolean
Queries aGtkExpander
and returns its current state.getLabel()
Fetches the text from a label widget.Retrieves the label widget for the frame.boolean
Returns whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.static Type
getType()
Get the GType of the Expander classboolean
Returns whether the label’s text is interpreted as Pango markup.boolean
Returns whether an underline in the text indicates a mnemonic.onActivate
(Expander.ActivateCallback handler) Activates theGtkExpander
.void
Sets the child widget of this Expander.void
setExpanded
(boolean expanded) Sets the state of the expander.void
Sets the text of the label of the expander tolabel
.void
setLabelWidget
(@Nullable Widget labelWidget) Set the label widget for the expander.void
setResizeToplevel
(boolean resizeToplevel) Sets whether the expander will resize the toplevel widget containing the expander upon resizing and collapsing.void
setUseMarkup
(boolean useMarkup) Sets whether the text of the label contains Pango markup.void
setUseUnderline
(boolean useUnderline) If true, an underline in the text indicates a mnemonic.static Expander
withMnemonic
(@Nullable String label) Creates a new expander usinglabel
as 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, 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, 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, unsetStateFlags
Methods 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, 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, withProperties
Methods inherited from class org.gnome.gobject.TypeInstance
callParent, callParent, getPrivate, readGClass, writeGClass
Methods inherited from class io.github.jwharm.javagi.base.ProxyInstance
equals, handle, hashCode
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.gnome.gtk.Accessible
announce, getAccessibleParent, getAccessibleRole, getAtContext, getBounds, getFirstAccessibleChild, getNextAccessibleSibling, getPlatformState, resetProperty, resetRelation, resetState, setAccessibleParent, updateNextAccessibleSibling, updateProperty, updateRelation, updateState
Methods 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 usinglabel
as the text of the label.- Parameters:
label
- the text of the label
-
Expander
public Expander()CallsExpander(java.lang.String)
with label =null
-
-
Method Details
-
getType
-
asParent
Returns this instance as if it were its parent type. This is mostly synonymous to the Javasuper
keyword, 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 usinglabel
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
Gets the child widget of this Expander.- Returns:
- the child widget of this Expander
-
getExpanded
public boolean getExpanded()Queries aGtkExpander
and returns its current state.Returns
true
if 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
-
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
Sets the child widget of this 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, andfalse
if 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
-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 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.Builder
object constructs aExpander
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withExpander.Builder.build()
.
-