Class CheckButton
- All Implemented Interfaces:
Proxy
,Accessible
,Actionable
,Buildable
,ConstraintTarget
GtkCheckButton
places a label next to an indicator.
A GtkCheckButton
is created by calling either CheckButton()
or withLabel(java.lang.String)
.
The state of a GtkCheckButton
can be set specifically using
setActive(boolean)
, and retrieved using
getActive()
.
Inconsistent state
In addition to "on" and "off", check buttons can be an
"in between" state that is neither on nor off. This can be used
e.g. when the user has selected a range of elements (such as some
text or spreadsheet cells) that are affected by a check button,
and the current values in that range are inconsistent.
To set a GtkCheckButton
to inconsistent state, use
setInconsistent(boolean)
.
Grouping
Check buttons can be grouped together, to form mutually exclusive
groups - only one of the buttons can be toggled at a time, and toggling
another one will switch the currently toggled one off.
Grouped check buttons use a different indicator, and are commonly referred to as *radio buttons*.
To add a GtkCheckButton
to a group, use setGroup(org.gnome.gtk.CheckButton)
.
When the code must keep track of the state of a group of radio buttons, it
is recommended to keep track of such state through a stateful
GAction
with a target for each button. Using the toggled
signals to keep
track of the group changes and state is discouraged.
Shortcuts and Gestures
GtkCheckButton
supports the following keyboard shortcuts:
␣
orEnter
activates the button.
CSS nodes
checkbutton[.text-button][.grouped]
├── check
╰── [label]
A GtkCheckButton
has a main node with name checkbutton. If the
Gtk.CheckButton:label
or Gtk.CheckButton:child
properties are set, it contains a child widget. The indicator node
is named check when no group is set, and radio if the checkbutton
is grouped together with other checkbuttons.
Accessibility
GtkCheckButton
uses the AccessibleRole.CHECKBOX
role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theActivateCallback
callback.static class
CheckButton.Builder<B extends CheckButton.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
static interface
Functional interface declaration of theToggledCallback
callback.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.Actionable
Actionable.ActionableImpl, Actionable.ActionableInterface
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 newGtkCheckButton
.CheckButton
(MemorySegment address) Create a CheckButton proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
activate()
protected CheckButton
asParent()
Returns this instance as if it were its parent type.static CheckButton.Builder
<? extends CheckButton.Builder> builder()
ACheckButton.Builder
object constructs aCheckButton
with the specified properties.void
Emits the "activate" signal.void
Emits the "toggled" signal.boolean
Returns whether the check button is active.getChild()
Gets the child widget of this CheckButton orNULL
ifCheckButton:label
is set.boolean
Returns whether the check button is in an inconsistent state.getLabel()
Returns the label of the check button orNULL
ifCheckButton:child
is set.static MemoryLayout
The memory layout of the native struct.static Type
getType()
Get the GType of the CheckButton classboolean
Returns whether underlines in the label indicate mnemonics.onActivate
(CheckButton.ActivateCallback handler) Emitted to when the check button is activated.onToggled
(CheckButton.ToggledCallback handler) Emitted when the buttons'sGtk.CheckButton:active
property changes.void
setActive
(boolean setting) Changes the check buttons active state.void
Sets the child widget of this CheckButton.void
setGroup
(@Nullable CheckButton group) Adds this CheckButton to the group ofgroup
.void
setInconsistent
(boolean inconsistent) Sets theGtkCheckButton
to inconsistent state.void
Sets the text of this CheckButton.void
setUseUnderline
(boolean setting) Sets whether underlines in the label indicate mnemonics.protected void
toggled()
static CheckButton
Creates a newGtkCheckButton
with the given text.static CheckButton
withMnemonic
(@Nullable String label) Creates a newGtkCheckButton
with the given text and 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, 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.Actionable
getActionName, getActionTargetValue, setActionName, setActionTarget, setActionTargetValue, setDetailedActionName
Methods inherited from interface org.gnome.gtk.Buildable
getBuildableId
-
Constructor Details
-
CheckButton
Create a CheckButton proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
CheckButton
public CheckButton()Creates a newGtkCheckButton
.
-
-
Method Details
-
getType
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
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. -
withLabel
Creates a newGtkCheckButton
with the given text.- Parameters:
label
- the text for the check button.- Returns:
- a new
GtkCheckButton
-
withMnemonic
Creates a newGtkCheckButton
with the given text and a mnemonic.- Parameters:
label
- The text of the button, with an underscore in front of the mnemonic character- Returns:
- a new
GtkCheckButton
-
getActive
public boolean getActive()Returns whether the check button is active.- Returns:
- whether the check button is active
-
getChild
Gets the child widget of this CheckButton orNULL
ifCheckButton:label
is set.- Returns:
- the child widget of this CheckButton
-
getInconsistent
public boolean getInconsistent()Returns whether the check button is in an inconsistent state.- Returns:
true
if this CheckButton is currently in an inconsistent state
-
getLabel
Returns the label of the check button orNULL
ifCheckButton:child
is set.- Returns:
- The label this CheckButton shows next
to the indicator. If no label is shown,
null
will be returned.
-
getUseUnderline
public boolean getUseUnderline()Returns whether underlines in the label indicate mnemonics.- Returns:
- The value of the
Gtk.CheckButton:use-underline
property. SeesetUseUnderline(boolean)
for details on how to set a new value.
-
setActive
public void setActive(boolean setting) Changes the check buttons active state.- Parameters:
setting
- the new value to set
-
setChild
Sets the child widget of this CheckButton.Note that by using this API, you take full responsibility for setting up the proper accessibility label and description information for this CheckButton. Most likely, you'll either set the accessibility label or description for this CheckButton explicitly, or you'll set a labelled-by or described-by relations from
child
to this CheckButton.- Parameters:
child
- the child widget
-
setGroup
Adds this CheckButton to the group ofgroup
.In a group of multiple check buttons, only one button can be active at a time. The behavior of a checkbutton in a group is also commonly known as a *radio button*.
Setting the group of a check button also changes the css name of the indicator widget's CSS node to 'radio'.
Setting up groups in a cycle leads to undefined behavior.
Note that the same effect can be achieved via the
Actionable
API, by using the same action with parameter type and state type 's' for all buttons in the group, and giving each button its own target value.- Parameters:
group
- anotherGtkCheckButton
to form a group with
-
setInconsistent
public void setInconsistent(boolean inconsistent) Sets theGtkCheckButton
to inconsistent state.You should turn off the inconsistent state again if the user checks the check button. This has to be done manually.
- Parameters:
inconsistent
-true
if state is inconsistent
-
setLabel
Sets the text of this CheckButton.If
Gtk.CheckButton:use-underline
istrue
, an underscore inlabel
is interpreted as mnemonic indicator, seesetUseUnderline(boolean)
for details on this behavior.- Parameters:
label
- The text shown next to the indicator, ornull
to show no text
-
setUseUnderline
public void setUseUnderline(boolean setting) Sets whether underlines in the label indicate mnemonics.If
setting
istrue
, an underscore character in this CheckButton's label indicates a mnemonic accelerator key. This behavior is similar toGtk.Label:use-underline
.- Parameters:
setting
- the new value to set
-
activate
protected void activate() -
toggled
protected void toggled() -
onActivate
public SignalConnection<CheckButton.ActivateCallback> onActivate(CheckButton.ActivateCallback handler) Emitted to when the check button is activated.The
::activate
signal onGtkCheckButton
is an action signal and emitting it causes the button to animate press then release.Applications should never connect to this signal, but use the
Gtk.CheckButton::toggled
signal.The default bindings for this signal are all forms of the
␣
andEnter
keys.- 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.CheckButton.ActivateCallback)
. -
onToggled
Emitted when the buttons'sGtk.CheckButton:active
property changes.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitToggled
public void emitToggled()Emits the "toggled" signal. SeeonToggled(org.gnome.gtk.CheckButton.ToggledCallback)
. -
builder
ACheckButton.Builder
object constructs aCheckButton
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withCheckButton.Builder.build()
.
-