Class SpinButton
- All Implemented Interfaces:
Proxy
,Accessible
,AccessibleRange
,Buildable
,CellEditable
,ConstraintTarget
,Editable
,Orientable
GtkSpinButton
is an ideal way to allow the user to set the
value of some attribute.
Rather than having to directly type a number into a GtkEntry
,
GtkSpinButton
allows the user to click on one of two arrows
to increment or decrement the displayed value. A value can still be
typed in, with the bonus that it can be checked to ensure it is in a
given range.
The main properties of a GtkSpinButton
are through an adjustment.
See the Adjustment
documentation for more details about
an adjustment's properties.
Note that GtkSpinButton
will by default make its entry large enough
to accommodate the lower and upper bounds of the adjustment. If this
is not desired, the automatic sizing can be turned off by explicitly
setting Gtk.Editable:width-chars
to a value != -1.
Using a GtkSpinButton to get an integer
// Provides a function to retrieve an integer value from a GtkSpinButton
// and creates a spin button to model percentage values.
int
grab_int_value (GtkSpinButton *button,
gpointer user_data)
{
return gtk_spin_button_get_value_as_int (button);
}
void
create_integer_spin_button (void)
{
GtkWidget *window, *button;
GtkAdjustment *adjustment;
adjustment = gtk_adjustment_new (50.0, 0.0, 100.0, 1.0, 5.0, 0.0);
window = gtk_window_new ();
// creates the spinbutton, with no decimal places
button = gtk_spin_button_new (adjustment, 1.0, 0);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
Using a GtkSpinButton to get a floating point value
// Provides a function to retrieve a floating point value from a
// GtkSpinButton, and creates a high precision spin button.
float
grab_float_value (GtkSpinButton *button,
gpointer user_data)
{
return gtk_spin_button_get_value (button);
}
void
create_floating_spin_button (void)
{
GtkWidget *window, *button;
GtkAdjustment *adjustment;
adjustment = gtk_adjustment_new (2.500, 0.0, 5.0, 0.001, 0.1, 0.0);
window = gtk_window_new ();
// creates the spinbutton, with three decimal places
button = gtk_spin_button_new (adjustment, 0.001, 3);
gtk_window_set_child (GTK_WINDOW (window), button);
gtk_window_present (GTK_WINDOW (window));
}
Shortcuts and Gestures
The following signals have default keybindings:
Gtk.SpinButton::change-value
CSS nodes
spinbutton.horizontal
├── text
│ ├── undershoot.left
│ ╰── undershoot.right
├── button.down
╰── button.up
spinbutton.vertical
├── button.up
├── text
│ ├── undershoot.left
│ ╰── undershoot.right
╰── button.down
GtkSpinButton
s main CSS node has the name spinbutton. It creates subnodes
for the entry and the two buttons, with these names. The button nodes have
the style classes .up and .down. The GtkText
subnodes (if present) are put
below the text node. The orientation of the spin button is reflected in
the .vertical or .horizontal style class on the main node.
Accessibility
GtkSpinButton
uses the AccessibleRole.SPIN_BUTTON
role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theActivateCallback
callback.static class
SpinButton.Builder<B extends SpinButton.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static interface
Functional interface declaration of theChangeValueCallback
callback.static interface
Functional interface declaration of theInputCallback
callback.static interface
Functional interface declaration of theOutputCallback
callback.static interface
Functional interface declaration of theValueChangedCallback
callback.static interface
Functional interface declaration of theWrappedCallback
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.AccessibleRange
AccessibleRange.AccessibleRangeImpl, AccessibleRange.AccessibleRangeInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Buildable
Buildable.BuildableIface, Buildable.BuildableImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.CellEditable
CellEditable.CellEditableIface, CellEditable.CellEditableImpl, CellEditable.EditingDoneCallback, CellEditable.RemoveWidgetCallback
Nested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Editable
Editable.ChangedCallback, Editable.DeleteTextCallback, Editable.EditableImpl, Editable.EditableInterface, Editable.InsertTextCallback
Nested classes/interfaces inherited from interface org.gnome.gtk.Orientable
Orientable.OrientableIface, Orientable.OrientableImpl
-
Constructor Summary
ConstructorDescriptionSpinButton
(MemorySegment address) Create a SpinButton proxy instance for the provided memory address.SpinButton
(@Nullable Adjustment adjustment, double climbRate, int digits) Creates a newGtkSpinButton
. -
Method Summary
Modifier and TypeMethodDescriptionprotected SpinButton
asParent()
Returns this instance as if it were its parent type.static SpinButton.Builder
<? extends SpinButton.Builder> builder()
ASpinButton.Builder
object constructs aSpinButton
with the specified properties.void
configure
(@Nullable Adjustment adjustment, double climbRate, int digits) Changes the properties of an existing spin button.void
Emits the "activate" signal.void
emitChangeValue
(ScrollType scroll) Emits the "change-value" signal.int
Emits the "input" signal.boolean
Emits the "output" signal.void
Emits the "value-changed" signal.void
Emits the "wrapped" signal.boolean
Retrieves the value set bysetActivatesDefault(boolean)
.Get the adjustment associated with aGtkSpinButton
.double
Returns the acceleration rate for repeated changes.int
Fetches the precision of this SpinButton.void
getIncrements
(@Nullable Out<Double> step, @Nullable Out<Double> page) Gets the current step and page the increments used by this SpinButton.boolean
Returns whether non-numeric text can be typed into the spin button.void
Gets the range allowed for this SpinButton.boolean
Returns whether the values are corrected to the nearest step.static Type
getType()
Get the GType of the SpinButton classGets the update behavior of a spin button.double
getValue()
Get the value in the this SpinButton.int
Get the value this SpinButton represented as an integer.boolean
getWrap()
Returns whether the spin button’s value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.onActivate
(SpinButton.ActivateCallback handler) Emitted when the spin button is activated.Emitted when the user initiates a value change.onInput
(SpinButton.InputCallback handler) Emitted to convert the users input into a double value.onOutput
(SpinButton.OutputCallback handler) Emitted to tweak the formatting of the value for display.Emitted when the value is changed.onWrapped
(SpinButton.WrappedCallback handler) Emitted right after the spinbutton wraps from its maximum to its minimum value or vice-versa.void
setActivatesDefault
(boolean activatesDefault) Sets whether activating the spin button will activate the default widget for the window containing the spin button.void
setAdjustment
(Adjustment adjustment) Replaces theGtkAdjustment
associated with this SpinButton.void
setClimbRate
(double climbRate) Sets the acceleration rate for repeated changes when you hold down a button or key.void
setDigits
(int digits) Set the precision to be displayed by this SpinButton.void
setIncrements
(double step, double page) Sets the step and page increments for spin_button.void
setNumeric
(boolean numeric) Sets the flag that determines if non-numeric text can be typed into the spin button.void
setRange
(double min, double max) Sets the minimum and maximum allowable values for this SpinButton.void
setSnapToTicks
(boolean snapToTicks) Sets the policy as to whether values are corrected to the nearest step increment when a spin button is activated after providing an invalid value.void
Sets the update behavior of a spin button.void
setValue
(double value) Sets the value of this SpinButton.void
setWrap
(boolean wrap) Sets the flag that determines if a spin button value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.void
Increment or decrement a spin button’s value in a specified direction by a specified amount.void
update()
Manually force an update of the spin button.static SpinButton
withRange
(double min, double max, double step) Creates a newGtkSpinButton
with the given properties.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
Methods inherited from interface org.gnome.gtk.CellEditable
editingDone, emitEditingDone, emitRemoveWidget, onEditingDone, onRemoveWidget, removeWidget, startEditing
Methods inherited from interface org.gnome.gtk.Editable
delegateGetAccessiblePlatformState, deleteSelection, deleteText, emitChanged, emitDeleteText, emitInsertText, finishDelegate, getAlignment, getChars, getDelegate, getEditable, getEnableUndo, getMaxWidthChars, getPosition, getSelectionBounds, getText, getWidthChars, initDelegate, insertText, onChanged, onDeleteText, onInsertText, selectRegion, setAlignment, setEditable, setEnableUndo, setMaxWidthChars, setPosition, setText, setWidthChars
Methods inherited from interface org.gnome.gtk.Orientable
getOrientation, setOrientation
-
Constructor Details
-
SpinButton
Create a SpinButton proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
SpinButton
Creates a newGtkSpinButton
.- Parameters:
adjustment
- theGtkAdjustment
that this spin button should useclimbRate
- specifies by how much the rate of change in the value will accelerate if you continue to hold down an up/down button or arrow keydigits
- the number of decimal places to display
-
-
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. -
withRange
Creates a newGtkSpinButton
with the given properties.This is a convenience constructor that allows creation of a numeric
GtkSpinButton
without manually creating an adjustment. The value is initially set to the minimum value and a page increment of 10 *step
is the default. The precision of the spin button is equivalent to the precision ofstep
.Note that the way in which the precision is derived works best if
step
is a power of ten. If the resulting precision is not suitable for your needs, usesetDigits(int)
to correct it.- Parameters:
min
- Minimum allowable valuemax
- Maximum allowable valuestep
- Increment added or subtracted by spinning the widget- Returns:
- The new
GtkSpinButton
-
configure
Changes the properties of an existing spin button.The adjustment, climb rate, and number of decimal places are updated accordingly.
- Parameters:
adjustment
- aGtkAdjustment
to replace the spin button’s existing adjustment, ornull
to leave its current adjustment unchangedclimbRate
- the new climb ratedigits
- the number of decimal places to display in the spin button
-
getActivatesDefault
public boolean getActivatesDefault()Retrieves the value set bysetActivatesDefault(boolean)
.- Returns:
true
if the spin button will activate the default widget
-
getAdjustment
Get the adjustment associated with aGtkSpinButton
.- Returns:
- the
GtkAdjustment
of this SpinButton
-
getClimbRate
public double getClimbRate()Returns the acceleration rate for repeated changes.- Returns:
- the acceleration rate
-
getDigits
public int getDigits()Fetches the precision of this SpinButton.- Returns:
- the current precision
-
getIncrements
-
getNumeric
public boolean getNumeric()Returns whether non-numeric text can be typed into the spin button.- Returns:
true
if only numeric text can be entered
-
getRange
Gets the range allowed for this SpinButton.- Parameters:
min
- location to store minimum allowed valuemax
- location to store maximum allowed value
-
getSnapToTicks
public boolean getSnapToTicks()Returns whether the values are corrected to the nearest step.- Returns:
true
if values are snapped to the nearest step
-
getUpdatePolicy
Gets the update behavior of a spin button.- Returns:
- the current update policy
-
getValue
public double getValue()Get the value in the this SpinButton.- Returns:
- the value of this SpinButton
-
getValueAsInt
public int getValueAsInt()Get the value this SpinButton represented as an integer.- Returns:
- the value of this SpinButton
-
getWrap
public boolean getWrap()Returns whether the spin button’s value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.- Returns:
true
if the spin button wraps around
-
setActivatesDefault
public void setActivatesDefault(boolean activatesDefault) Sets whether activating the spin button will activate the default widget for the window containing the spin button.See
Gtk.SpinButton::activate
for what counts as activation.- Parameters:
activatesDefault
-true
to activate window’s default widget on activation
-
setAdjustment
Replaces theGtkAdjustment
associated with this SpinButton.- Parameters:
adjustment
- aGtkAdjustment
to replace the existing adjustment
-
setClimbRate
public void setClimbRate(double climbRate) Sets the acceleration rate for repeated changes when you hold down a button or key.- Parameters:
climbRate
- the rate of acceleration, must be >= 0
-
setDigits
public void setDigits(int digits) Set the precision to be displayed by this SpinButton.Up to 20 digit precision is allowed.
- Parameters:
digits
- the number of digits after the decimal point to be displayed for the spin button’s value
-
setIncrements
public void setIncrements(double step, double page) Sets the step and page increments for spin_button.This affects how quickly the value changes when the spin button’s arrows are activated.
- Parameters:
step
- increment applied for a button 1 press.page
- increment applied for a button 2 press.
-
setNumeric
public void setNumeric(boolean numeric) Sets the flag that determines if non-numeric text can be typed into the spin button.- Parameters:
numeric
- flag indicating if only numeric entry is allowed
-
setRange
public void setRange(double min, double max) Sets the minimum and maximum allowable values for this SpinButton.If the current value is outside this range, it will be adjusted to fit within the range, otherwise it will remain unchanged.
- Parameters:
min
- minimum allowable valuemax
- maximum allowable value
-
setSnapToTicks
public void setSnapToTicks(boolean snapToTicks) Sets the policy as to whether values are corrected to the nearest step increment when a spin button is activated after providing an invalid value.- Parameters:
snapToTicks
- a flag indicating if invalid values should be corrected
-
setUpdatePolicy
Sets the update behavior of a spin button.This determines whether the spin button is always updated or only when a valid value is set.
- Parameters:
policy
- aGtkSpinButtonUpdatePolicy
value
-
setValue
public void setValue(double value) Sets the value of this SpinButton.- Parameters:
value
- the new value
-
setWrap
public void setWrap(boolean wrap) Sets the flag that determines if a spin button value wraps around to the opposite limit when the upper or lower limit of the range is exceeded.- Parameters:
wrap
- a flag indicating if wrapping behavior is performed
-
spin
Increment or decrement a spin button’s value in a specified direction by a specified amount.- Parameters:
direction
- aGtkSpinType
indicating the direction to spinincrement
- step increment to apply in the specified direction
-
update
public void update()Manually force an update of the spin button. -
onActivate
public SignalConnection<SpinButton.ActivateCallback> onActivate(SpinButton.ActivateCallback handler) Emitted when the spin button is activated.The keybindings for this signal are all forms of the
Enter
key.If the
Enter
key results in the value being committed to the spin button, then activation does not occur untilEnter
is pressed again.- 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.SpinButton.ActivateCallback)
. -
onChangeValue
public SignalConnection<SpinButton.ChangeValueCallback> onChangeValue(SpinButton.ChangeValueCallback handler) Emitted when the user initiates a value change.This is a keybinding signal.
Applications should not connect to it, but may emit it with g_signal_emit_by_name() if they need to control the cursor programmatically.
The default bindings for this signal are Up/Down and PageUp/PageDown.
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChangeValue
Emits the "change-value" signal. SeeonChangeValue(org.gnome.gtk.SpinButton.ChangeValueCallback)
. -
onInput
Emitted to convert the users input into a double value.The signal handler is expected to use
Editable.getText()
to retrieve the text of the spinbutton and setnewValue
to the new value.The default conversion uses g_strtod().
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitInput
Emits the "input" signal. SeeonInput(org.gnome.gtk.SpinButton.InputCallback)
. -
onOutput
Emitted to tweak the formatting of the value for display.// show leading zeros static gboolean on_output (GtkSpinButton *spin, gpointer data) { char *text; int value; value = gtk_spin_button_get_value_as_int (spin); text = g_strdup_printf ("%02d", value); gtk_editable_set_text (GTK_EDITABLE (spin), text): g_free (text); return TRUE; }
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitOutput
public boolean emitOutput()Emits the "output" signal. SeeonOutput(org.gnome.gtk.SpinButton.OutputCallback)
. -
onValueChanged
public SignalConnection<SpinButton.ValueChangedCallback> onValueChanged(SpinButton.ValueChangedCallback handler) Emitted when the value is changed.Also see the
Gtk.SpinButton::output
signal.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitValueChanged
public void emitValueChanged()Emits the "value-changed" signal. SeeonValueChanged(org.gnome.gtk.SpinButton.ValueChangedCallback)
. -
onWrapped
Emitted right after the spinbutton wraps from its maximum to its minimum value or vice-versa.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitWrapped
public void emitWrapped()Emits the "wrapped" signal. SeeonWrapped(org.gnome.gtk.SpinButton.WrappedCallback)
. -
builder
ASpinButton.Builder
object constructs aSpinButton
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withSpinButton.Builder.build()
.
-