Class MenuButton
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,ConstraintTarget
GtkMenuButton
widget is used to display a popup when clicked.
This popup can be provided either as a GtkPopover
or as an abstract
GMenuModel
.
The GtkMenuButton
widget can show either an icon (set with the
Gtk.MenuButton:icon-name
property) or a label (set with the
Gtk.MenuButton:label
property). If neither is explicitly set,
a Image
is automatically created, using an arrow image oriented
according to Gtk.MenuButton:direction
or the generic
“open-menu-symbolic” icon if the direction is not set.
The positioning of the popup is determined by the
Gtk.MenuButton:direction
property of the menu button.
For menus, the Gtk.Widget:halign
and Gtk.Widget:valign
properties of the menu are also taken into account. For example, when the
direction is ArrowType.DOWN
and the horizontal alignment is Align.START
,
the menu will be positioned below the button, with the starting edge
(depending on the text direction) of the menu aligned with the starting
edge of the button. If there is not enough space below the button, the
menu is popped up above the button instead. If the alignment would move
part of the menu offscreen, it is “pushed in”.
| | start | center | end | | - | --- | --- | --- | | down | | | | | up | | | | | left | | | | | right | | | |
CSS nodes
menubutton
╰── button.toggle
╰── <content>
╰── [arrow]
GtkMenuButton
has a single CSS node with name menubutton
which contains a button
node with a .toggle
style class.
If the button contains an icon, it will have the .image-button
style class,
if it contains text, it will have .text-button
style class. If an arrow is
visible in addition to an icon, text or a custom child, it will also have
.arrow-button
style class.
Inside the toggle button content, there is an arrow
node for
the indicator, which will carry one of the .none
, .up
, .down
,
.left
or .right
style classes to indicate the direction that
the menu will appear in. The CSS is expected to provide a suitable
image for each of these cases using the -gtk-icon-source
property.
Optionally, the menubutton
node can carry the .circular
style class
to request a round appearance.
Accessibility
GtkMenuButton
uses the AccessibleRole.BUTTON
role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theActivateCallback
callback.static class
MenuButton.Builder<B extends MenuButton.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
ConstructorDescriptionCreates a newGtkMenuButton
widget with downwards-pointing arrow as the only child.MenuButton
(MemorySegment address) Create a MenuButton proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected MenuButton
asParent()
Returns this instance as if it were its parent type.static MenuButton.Builder
<? extends MenuButton.Builder> builder()
AMenuButton.Builder
object constructs aMenuButton
with the specified properties.void
Emits the "activate" signal.boolean
Returns whether the menu button is active.boolean
Gets whether to show a dropdown arrow even when using an icon or a custom child.Returns the direction the popup will be pointing at when popped up.boolean
Retrieves whether the button can be smaller than the natural size of its contents.getChild()
Gets the child widget of this MenuButton.boolean
Returns whether the button has a frame.Gets the name of the icon shown in the button.getLabel()
Gets the label shown in the buttonReturns theGMenuModel
used to generate the popup.Returns theGtkPopover
that pops out of the button.boolean
Returns whether the menu button acts as a primary menu.static Type
getType()
Get the GType of the MenuButton classboolean
Returns whether an embedded underline in the text indicates a mnemonic.onActivate
(MenuButton.ActivateCallback handler) Emitted to when the menu button is activated.void
popdown()
Dismiss the menu.void
popup()
Pop up the menu.void
setActive
(boolean active) Sets whether the menu button is active.void
setAlwaysShowArrow
(boolean alwaysShowArrow) Sets whether to show a dropdown arrow even when using an icon or a custom child.void
setCanShrink
(boolean canShrink) Sets whether the button size can be smaller than the natural size of its contents.void
Sets the child widget of this MenuButton.void
setCreatePopupFunc
(@Nullable MenuButtonCreatePopupFunc func) Setsfunc
to be called when a popup is about to be shown.void
setDirection
(ArrowType direction) Sets the direction in which the popup will be popped up.void
setHasFrame
(boolean hasFrame) Sets the style of the button.void
setIconName
(String iconName) Sets the name of an icon to show inside the menu button.void
Sets the label to show inside the menu button.void
setMenuModel
(@Nullable MenuModel menuModel) Sets theGMenuModel
from which the popup will be constructed.void
setPopover
(@Nullable Widget popover) Sets theGtkPopover
that will be popped up when the this MenuButton is clicked.void
setPrimary
(boolean primary) Sets whether menu button acts as a primary menu.void
setUseUnderline
(boolean useUnderline) If true, an underline in the text indicates a mnemonic.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
-
MenuButton
Create a MenuButton proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
MenuButton
public MenuButton()Creates a newGtkMenuButton
widget with downwards-pointing arrow as the only child.You can replace the child widget with another
GtkWidget
should you wish to.
-
-
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. -
getActive
public boolean getActive()Returns whether the menu button is active.- Returns:
- TRUE if the button is active
-
getAlwaysShowArrow
public boolean getAlwaysShowArrow()Gets whether to show a dropdown arrow even when using an icon or a custom child.- Returns:
- whether to show a dropdown arrow even when using an icon or a custom child.
-
getCanShrink
public boolean getCanShrink()Retrieves whether the button can be smaller than the natural size of its contents.- Returns:
- true if the button can shrink, and false otherwise
-
getChild
Gets the child widget of this MenuButton.- Returns:
- the child widget of this MenuButton
-
getArrowDirection
Returns the direction the popup will be pointing at when popped up.- Returns:
- a
GtkArrowType
value
-
getHasFrame
public boolean getHasFrame()Returns whether the button has a frame.- Returns:
true
if the button has a frame
-
getIconName
Gets the name of the icon shown in the button.- Returns:
- the name of the icon shown in the button
-
getLabel
-
getMenuModel
Returns theGMenuModel
used to generate the popup.- Returns:
- a
GMenuModel
-
getPopover
Returns theGtkPopover
that pops out of the button.If the button is not using a
GtkPopover
, this function returnsnull
.- Returns:
- a
GtkPopover
ornull
-
getPrimary
public boolean getPrimary()Returns whether the menu button acts as a primary menu.- Returns:
true
if the button is a primary menu
-
getUseUnderline
public boolean getUseUnderline()Returns whether an embedded underline in the text indicates a mnemonic.- Returns:
true
whether an embedded underline in the text indicates the mnemonic accelerator keys.
-
popdown
public void popdown()Dismiss the menu. -
popup
public void popup()Pop up the menu. -
setActive
public void setActive(boolean active) Sets whether the menu button is active.- Parameters:
active
- whether the menu button is active
-
setAlwaysShowArrow
public void setAlwaysShowArrow(boolean alwaysShowArrow) Sets whether to show a dropdown arrow even when using an icon or a custom child.- Parameters:
alwaysShowArrow
- whether to show a dropdown arrow even when using an icon or a custom child
-
setCanShrink
public void setCanShrink(boolean canShrink) Sets whether the button size can be smaller than the natural size of its contents.For text buttons, setting
canShrink
to true will ellipsize the label.For icon buttons, this function has no effect.
- Parameters:
canShrink
- whether the button can shrink
-
setChild
Sets the child widget of this MenuButton.Setting a child resets
Gtk.MenuButton:label
andGtk.MenuButton:icon-name
.If
Gtk.MenuButton:always-show-arrow
is set toTRUE
andGtk.MenuButton:direction
is notGTK_ARROW_NONE
, a dropdown arrow will be shown next to the child.- Parameters:
child
- the child widget
-
setCreatePopupFunc
Setsfunc
to be called when a popup is about to be shown.func
should use one ofto set a popup for this MenuButton. If
func
is non-null
, this MenuButton will always be sensitive.Using this function will not reset the menu widget attached to this MenuButton. Instead, this can be done manually in
func
.- Parameters:
func
- function to call when a popup is about to be shown, but none has been provided via other means, ornull
to reset to default behavior
-
setDirection
Sets the direction in which the popup will be popped up.If the button is automatically populated with an arrow icon, its direction will be changed to match.
If the does not fit in the available space in the given direction, GTK will its best to keep it inside the screen and fully visible.
If you pass
ArrowType.NONE
for adirection
, the popup will behave as if you passedArrowType.DOWN
(although you won’t see any arrows).- Parameters:
direction
- aGtkArrowType
-
setHasFrame
public void setHasFrame(boolean hasFrame) Sets the style of the button.- Parameters:
hasFrame
- whether the button should have a visible frame
-
setIconName
Sets the name of an icon to show inside the menu button.Setting icon name resets
Gtk.MenuButton:label
andGtk.MenuButton:child
.If
Gtk.MenuButton:always-show-arrow
is set toTRUE
andGtk.MenuButton:direction
is notGTK_ARROW_NONE
, a dropdown arrow will be shown next to the icon.- Parameters:
iconName
- the icon name
-
setLabel
Sets the label to show inside the menu button.Setting a label resets
Gtk.MenuButton:icon-name
andGtk.MenuButton:child
.If
Gtk.MenuButton:direction
is notGTK_ARROW_NONE
, a dropdown arrow will be shown next to the label.- Parameters:
label
- the label
-
setMenuModel
Sets theGMenuModel
from which the popup will be constructed.If
menuModel
isnull
, the button is disabled.A
Popover
will be created from the menu model withPopoverMenu.fromModel(org.gnome.gio.MenuModel)
. Actions will be connected as documented for this function.If
Gtk.MenuButton:popover
is already set, it will be dissociated from the this MenuButton, and the property is set tonull
.- Parameters:
menuModel
- aGMenuModel
, ornull
to unset and disable the button
-
setPopover
Sets theGtkPopover
that will be popped up when the this MenuButton is clicked.If
popover
isnull
, the button is disabled.If
Gtk.MenuButton:menu-model
is set, the menu model is dissociated from the this MenuButton, and the property is set tonull
.- Parameters:
popover
- aGtkPopover
, ornull
to unset and disable the button
-
setPrimary
public void setPrimary(boolean primary) Sets whether menu button acts as a primary menu.Primary menus can be opened with the
F10
key.- Parameters:
primary
- whether the menubutton should act as a primary menu
-
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
public SignalConnection<MenuButton.ActivateCallback> onActivate(MenuButton.ActivateCallback handler) Emitted to when the menu button is activated.The
::activate
signal onGtkMenuButton
is an action signal and emitting it causes the button to pop up its menu.- 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.MenuButton.ActivateCallback)
. -
builder
AMenuButton.Builder
object constructs aMenuButton
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withMenuButton.Builder.build()
.
-