Class CheckButton
- All Implemented Interfaces:
Accessible,Actionable,Buildable,ConstraintTarget,Proxy
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:
␣orEnteractivates 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 Gtk.AccessibleRole.checkbox role.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceFunctional interface declaration of theActivateCallbackcallback.static classCheckButton.Builder<B extends CheckButton.Builder<B>>Inner class implementing a builder pattern to construct a GObject with properties.static classstatic interfaceFunctional interface declaration of theToggledCallbackcallback.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.Actionable
Actionable.Actionable$Impl, Actionable.ActionableInterfaceNested 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
ConstructorsConstructorDescriptionCreates a new CheckButton.CheckButton(MemorySegment address) Create a CheckButton proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidactivate()protected CheckButtonasParent()Returns this instance as if it were its parent type.static CheckButton.Builder<? extends CheckButton.Builder> builder()ACheckButton.Builderobject constructs aCheckButtonwith the specified properties.voidEmits the "activate" signal.voidEmits the "toggled" signal.booleanReturns whether the check button is active.@Nullable WidgetgetChild()Gets the child widget of this CheckButton orNULLifCheckButton:labelis set.booleanReturns whether the check button is in an inconsistent state.@Nullable StringgetLabel()Returns the label of the check button orNULLifCheckButton:childis set.static MemoryLayoutThe memory layout of the native struct.static @Nullable TypegetType()Get the GType of the CheckButton classbooleanReturns 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:activeproperty changes.voidsetActive(boolean setting) Changes the check buttons active state.voidSets the child widget ofbutton.voidsetGroup(@Nullable CheckButton group) Adds this CheckButton to the group ofgroup.voidsetInconsistent(boolean inconsistent) Sets theGtkCheckButtonto inconsistent state.voidSets the text ofself.voidsetUseUnderline(boolean setting) Sets whether underlines in the label indicate mnemonics.protected voidtoggled()static CheckButtonCreates a newGtkCheckButtonwith the given text.static CheckButtonwithMnemonic(@Nullable String label) Creates a newGtkCheckButtonwith 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, getLimitEvents, 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, 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.Actionable
getActionName, getActionTargetValue, setActionName, setActionTarget, setActionTargetValue, setDetailedActionNameMethods 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 new CheckButton.
-
-
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 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. -
withLabel
Creates a newGtkCheckButtonwith the given text.- Parameters:
label- the text for the check button.- Returns:
- a new
GtkCheckButton
-
withMnemonic
Creates a newGtkCheckButtonwith 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 orNULLifCheckButton:labelis set.- Returns:
- the child widget of this CheckButton
- Since:
- 4.8
-
getInconsistent
public boolean getInconsistent()Returns whether the check button is in an inconsistent state.- Returns:
trueif this CheckButton is currently in an inconsistent state
-
getLabel
Returns the label of the check button orNULLifCheckButton:childis set.- Returns:
- The label this CheckButton shows next
to the indicator. If no label is shown,
nullwill be returned.
-
getUseUnderline
public boolean getUseUnderline()Returns whether underlines in the label indicate mnemonics.- Returns:
- The value of the
Gtk.CheckButton:use-underlineproperty. 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 ofbutton.Note that by using this API, you take full responsibility for setting up the proper accessibility label and description information for
button.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 fromchildtobutton.- Parameters:
child- the child widget- Since:
- 4.8
-
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
ActionableAPI, 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- anotherGtkCheckButtonto form a group with
-
setInconsistent
public void setInconsistent(boolean inconsistent) Sets theGtkCheckButtonto 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-trueif state is inconsistent
-
setLabel
Sets the text ofself.If
Gtk.CheckButton:use-underlineistrue, an underscore inlabelis interpreted as mnemonic indicator, seesetUseUnderline(boolean)for details on this behavior.- Parameters:
label- The text shown next to the indicator, ornullto show no text
-
setUseUnderline
public void setUseUnderline(boolean setting) Sets whether underlines in the label indicate mnemonics.If
settingistrue, an underscore character inself'slabel 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
::activatesignal onGtkCheckButtonis 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::toggledsignal.The default bindings for this signal are all forms of the
␣andEnterkeys.- Parameters:
handler- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- Since:
- 4.2
- See Also:
-
emitActivate
public void emitActivate()Emits the "activate" signal. SeeonActivate(org.gnome.gtk.CheckButton.ActivateCallback). -
onToggled
Emitted when the buttons'sGtk.CheckButton:activeproperty 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.Builderobject constructs aCheckButtonwith the specified properties. Use the variousset...()methods to set properties, and finish construction withCheckButton.Builder.build().- Returns:
- the builder object
-