Class ComboBox
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,CellEditable
,CellLayout
,ConstraintTarget
- Direct Known Subclasses:
ComboBoxText
GtkComboBox
is a widget that allows the user to choose from a list of
valid choices.
The GtkComboBox
displays the selected choice; when activated, the
GtkComboBox
displays a popup which allows the user to make a new choice.
The GtkComboBox
uses the model-view pattern; the list of valid choices
is specified in the form of a tree model, and the display of the choices
can be adapted to the data in the model by using cell renderers, as you
would in a tree view. This is possible since GtkComboBox
implements the
CellLayout
interface. The tree model holding the valid
choices is not restricted to a flat list, it can be a real tree, and the
popup will reflect the tree structure.
To allow the user to enter values not in the model, the
Gtk.ComboBox:has-entry
property allows the GtkComboBox
to
contain a Entry
. This entry can be accessed by calling
getChild()
on the combo box.
For a simple list of textual choices, the model-view API of GtkComboBox
can be a bit overwhelming. In this case, ComboBoxText
offers
a simple alternative. Both GtkComboBox
and GtkComboBoxText
can contain
an entry.
CSS nodes
combobox
├── box.linked
│ ╰── button.combo
│ ╰── box
│ ├── cellview
│ ╰── arrow
╰── window.popup
A normal combobox contains a box with the .linked class, a button with the .combo class and inside those buttons, there are a cellview and an arrow.
combobox
├── box.linked
│ ├── entry.combo
│ ╰── button.combo
│ ╰── box
│ ╰── arrow
╰── window.popup
A GtkComboBox
with an entry has a single CSS node with name combobox.
It contains a box with the .linked class. That box contains an entry and
a button, both with the .combo class added. The button also contains another
node with name arrow.
Accessibility
GtkComboBox
uses the AccessibleRole.COMBO_BOX
role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Deprecated.Functional interface declaration of theActivateCallback
callback.static class
ComboBox.Builder<B extends ComboBox.Builder<B>>
Deprecated.Inner class implementing a builder pattern to construct a GObject with properties.static interface
Deprecated.Functional interface declaration of theChangedCallback
callback.static class
Deprecated.static interface
Deprecated.Functional interface declaration of theFormatEntryTextCallback
callback.static interface
Deprecated.Functional interface declaration of theMoveActiveCallback
callback.static interface
Deprecated.Functional interface declaration of thePopdownCallback
callback.static interface
Deprecated.Functional interface declaration of thePopupCallback
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.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.CellLayout
CellLayout.CellLayoutIface, CellLayout.CellLayoutImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
-
Constructor Summary
ConstructorDescriptionComboBox()
Deprecated.ComboBox
(MemorySegment address) Deprecated.Create a ComboBox proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
activate()
Deprecated.protected ComboBox
asParent()
Deprecated.Returns this instance as if it were its parent type.static ComboBox.Builder
<? extends ComboBox.Builder> builder()
Deprecated.AComboBox.Builder
object constructs aComboBox
with the specified properties.protected void
changed()
Deprecated.Signal is emitted when the active item is changed.void
Deprecated.Emits the "activate" signal.void
Deprecated.Emits the "changed" signal.emitFormatEntryText
(String path) Deprecated.Emits the "format-entry-text" signal.void
emitMoveActive
(ScrollType scrollType) Deprecated.Emits the "move-active" signal.boolean
Deprecated.Emits the "popdown" signal.void
Deprecated.Emits the "popup" signal.protected String
formatEntryText
(String path) Deprecated.Signal which allows you to change how the text displayed in a combo box’s entry is displayed.int
Deprecated.UseDropDown
Deprecated.UseDropDown
boolean
getActiveIter
(TreeIter iter) Deprecated.UseDropDown
Deprecated.UseDropDown
getChild()
Deprecated.UseDropDown
int
Deprecated.UseDropDown
boolean
Deprecated.UseDropDown
int
Deprecated.UseDropDown
static MemoryLayout
Deprecated.The memory layout of the native struct.getModel()
Deprecated.UseDropDown
boolean
Deprecated.UseDropDown
Deprecated.UseDropDown
static Type
getType()
Deprecated.Get the GType of the ComboBox classonActivate
(ComboBox.ActivateCallback handler) Deprecated.Emitted to when the combo box is activated.onChanged
(ComboBox.ChangedCallback handler) Deprecated.Emitted when the active item is changed.Deprecated.Emitted to allow changing how the text in a combo box's entry is displayed.onMoveActive
(ComboBox.MoveActiveCallback handler) Deprecated.Emitted to move the active selection.onPopdown
(ComboBox.PopdownCallback handler) Deprecated.Emitted to popdown the combo box list.onPopup
(ComboBox.PopupCallback handler) Deprecated.Emitted to popup the combo box list.void
popdown()
Deprecated.UseDropDown
void
popup()
Deprecated.UseDropDown
void
popupForDevice
(Device device) Deprecated.UseDropDown
void
setActive
(int index) Deprecated.UseDropDown
boolean
setActiveId
(@Nullable String activeId) Deprecated.UseDropDown
void
setActiveIter
(@Nullable TreeIter iter) Deprecated.UseDropDown
void
setButtonSensitivity
(SensitivityType sensitivity) Deprecated.UseDropDown
void
Deprecated.UseDropDown
void
setEntryTextColumn
(int textColumn) Deprecated.UseDropDown
void
setIdColumn
(int idColumn) Deprecated.UseDropDown
void
Deprecated.UseDropDown
void
setPopupFixedWidth
(boolean fixed) Deprecated.UseDropDown
void
setRowSeparatorFunc
(@Nullable TreeViewRowSeparatorFunc func) Deprecated.UseDropDown
static ComboBox
Deprecated.UseDropDown
static ComboBox
Deprecated.UseDropDown
static ComboBox
withModelAndEntry
(TreeModel model) Deprecated.UseDropDown
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.Buildable
getBuildableId
Methods inherited from interface org.gnome.gtk.CellEditable
editingDone, emitEditingDone, emitRemoveWidget, onEditingDone, onRemoveWidget, removeWidget, startEditing
Methods inherited from interface org.gnome.gtk.CellLayout
addAttribute, clear, clearAttributes, getArea, getCells, packEnd, packStart, reorder, setAttributes, setCellDataFunc
-
Constructor Details
-
ComboBox
Deprecated.Create a ComboBox proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
ComboBox
-
-
Method Details
-
getType
-
getMemoryLayout
Deprecated.The memory layout of the native struct.- Returns:
- the memory layout
-
asParent
Deprecated.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. -
withEntry
Deprecated.UseDropDown
Creates a new emptyGtkComboBox
with an entry.In order to use a combo box with entry, you need to tell it which column of the model contains the text for the entry by calling
setEntryTextColumn(int)
.- Returns:
- A new
GtkComboBox
-
withModel
Deprecated.UseDropDown
Creates a newGtkComboBox
with a model.- Parameters:
model
- aGtkTreeModel
- Returns:
- A new
GtkComboBox
-
withModelAndEntry
Deprecated.UseDropDown
Creates a new emptyGtkComboBox
with an entry and a model.See also
withEntry()
.- Parameters:
model
- AGtkTreeModel
- Returns:
- A new
GtkComboBox
-
getActive
Deprecated.UseDropDown
Returns the index of the currently active item.If the model is a non-flat treemodel, and the active item is not an immediate child of the root of the tree, this function returns
gtk_tree_path_get_indices (path)[0]
, wherepath
is theGtk.TreePath
of the active item.- Returns:
- An integer which is the index of the currently active item, or -1 if there’s no active item
-
getActiveId
Deprecated.UseDropDown
Returns the ID of the active row of this ComboBox.This value is taken from the active row and the column specified by the
Gtk.ComboBox:id-column
property of this ComboBox (seesetIdColumn(int)
).The returned value is an interned string which means that you can compare the pointer by value to other interned strings and that you must not free it.
If the
Gtk.ComboBox:id-column
property of this ComboBox is not set, or if no row is active, or if the active row has anull
ID value, thennull
is returned.- Returns:
- the ID of the active row
-
getActiveIter
Deprecated.UseDropDown
Setsiter
to point to the currently active item.If no item is active,
iter
is left unchanged.- Parameters:
iter
- AGtkTreeIter
- Returns:
true
ifiter
was set,false
otherwise
-
getButtonSensitivity
Deprecated.UseDropDown
Returns whether the combo box sets the dropdown button sensitive or not when there are no items in the model.- Returns:
SensitivityType.ON
if the dropdown button is sensitive when the model is empty,SensitivityType.OFF
if the button is always insensitive orSensitivityType.AUTO
if it is only sensitive as long as the model has one item to be selected.
-
getChild
Deprecated.UseDropDown
Gets the child widget of this ComboBox.- Returns:
- the child widget of this ComboBox
-
getEntryTextColumn
Deprecated.UseDropDown
Returns the column which this ComboBox is using to get the strings from to display in the internal entry.- Returns:
- A column in the data source model of this ComboBox.
-
getHasEntry
Deprecated.UseDropDown
Returns whether the combo box has an entry.- Returns:
- whether there is an entry in this ComboBox.
-
getIdColumn
Deprecated.UseDropDown
Returns the column which this ComboBox is using to get string IDs for values from.- Returns:
- A column in the data source model of this ComboBox.
-
getModel
Deprecated.UseDropDown
Returns theGtkTreeModel
of this ComboBox.- Returns:
- A
GtkTreeModel
which was passed during construction.
-
getPopupFixedWidth
Deprecated.UseDropDown
Gets whether the popup uses a fixed width.- Returns:
true
if the popup uses a fixed width
-
getRowSeparatorFunc
Deprecated.UseDropDown
Returns the current row separator function.- Returns:
- the current row separator function.
-
popdown
Deprecated.UseDropDown
Hides the menu or dropdown list of this ComboBox.This function is mostly intended for use by accessibility technologies; applications should have little use for it.
-
popup
Deprecated.UseDropDown
Pops up the menu or dropdown list of this ComboBox.This function is mostly intended for use by accessibility technologies; applications should have little use for it.
Before calling this, this ComboBox must be mapped, or nothing will happen.
-
popupForDevice
Deprecated.UseDropDown
Pops up the menu of this ComboBox.Note that currently this does not do anything with the device, as it was previously only used for list-mode combo boxes, and those were removed in GTK 4. However, it is retained in case similar functionality is added back later.
- Parameters:
device
- aGdkDevice
-
setActive
Deprecated.UseDropDown
Sets the active item of this ComboBox to be the item atindex
.- Parameters:
index
- An index in the model passed during construction, or -1 to have no active item
-
setActiveId
Deprecated.UseDropDown
Changes the active row of this ComboBox to the one that has an ID equal toactiveId
.If
activeId
isnull
, the active row is unset. Rows having anull
ID string cannot be made active by this function.If the
Gtk.ComboBox:id-column
property of this ComboBox is unset or if no row has the given ID then the function does nothing and returnsfalse
.- Parameters:
activeId
- the ID of the row to select- Returns:
true
if a row with a matching ID was found. If anull
activeId
was given to unset the active row, the function always returnstrue
.
-
setActiveIter
Deprecated.UseDropDown
Sets the current active item to be the one referenced byiter
.If
iter
isnull
, the active item is unset.- Parameters:
iter
- TheGtkTreeIter
-
setButtonSensitivity
Deprecated.UseDropDown
Sets whether the dropdown button of the combo box should update its sensitivity depending on the model contents.- Parameters:
sensitivity
- specify the sensitivity of the dropdown button
-
setChild
Deprecated.UseDropDown
Sets the child widget of this ComboBox.- Parameters:
child
- the child widget
-
setEntryTextColumn
Deprecated.UseDropDown
Sets the model column which this ComboBox should use to get strings from to betextColumn
.For this column no separate
CellRenderer
is needed.The column
textColumn
in the model of this ComboBox must be of typeG_TYPE_STRING
.This is only relevant if this ComboBox has been created with
Gtk.ComboBox:has-entry
astrue
.- Parameters:
textColumn
- A column inmodel
to get the strings from for the internal entry
-
setIdColumn
Deprecated.UseDropDown
Sets the model column which this ComboBox should use to get string IDs for values from.The column
idColumn
in the model of this ComboBox must be of typeG_TYPE_STRING
.- Parameters:
idColumn
- A column inmodel
to get string IDs for values from
-
setModel
Deprecated.UseDropDown
Sets the model used by this ComboBox to bemodel
.Will unset a previously set model (if applicable). If model is
null
, then it will unset the model.Note that this function does not clear the cell renderers, you have to call
CellLayout.clear()
yourself if you need to set up different cell renderers for the new model.- Parameters:
model
- AGtkTreeModel
-
setPopupFixedWidth
Deprecated.UseDropDown
Specifies whether the popup’s width should be a fixed width.If
fixed
istrue
, the popup's width is set to match the allocated width of the combo box.- Parameters:
fixed
- whether to use a fixed popup width
-
setRowSeparatorFunc
Deprecated.UseDropDown
Sets the row separator function, which is used to determine whether a row should be drawn as a separator.If the row separator function is
null
, no separators are drawn. This is the default value.- Parameters:
func
- aGtkTreeViewRowSeparatorFunc
-
activate
protected void activate()Deprecated. -
changed
protected void changed()Deprecated.Signal is emitted when the active item is changed. -
formatEntryText
-
onActivate
Deprecated.Emitted to when the combo box is activated.The
::activate
signal onGtkComboBox
is an action signal and emitting it causes the combo box to pop up its dropdown.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitActivate
public void emitActivate()Deprecated.Emits the "activate" signal. SeeonActivate(org.gnome.gtk.ComboBox.ActivateCallback)
. -
onChanged
Deprecated.Emitted when the active item is changed.The can be due to the user selecting a different item from the list, or due to a call to
setActiveIter(org.gnome.gtk.TreeIter)
. It will also be emitted while typing into the entry of a combo box with an entry.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitChanged
public void emitChanged()Deprecated.Emits the "changed" signal. SeeonChanged(org.gnome.gtk.ComboBox.ChangedCallback)
. -
onFormatEntryText
public SignalConnection<ComboBox.FormatEntryTextCallback> onFormatEntryText(ComboBox.FormatEntryTextCallback handler) Deprecated.Emitted to allow changing how the text in a combo box's entry is displayed.See
Gtk.ComboBox:has-entry
.Connect a signal handler which returns an allocated string representing
path
. That string will then be used to set the text in the combo box's entry. The default signal handler uses the text from theGtk.ComboBox:entry-text-column
model column.Here's an example signal handler which fetches data from the model and displays it in the entry.
static char * format_entry_text_callback (GtkComboBox *combo, const char *path, gpointer user_data) { GtkTreeIter iter; GtkTreeModel model; double value; model = gtk_combo_box_get_model (combo); gtk_tree_model_get_iter_from_string (model, &iter, path); gtk_tree_model_get (model, &iter, THE_DOUBLE_VALUE_COLUMN, &value, -1); return g_strdup_printf ("%g", value); }
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitFormatEntryText
Deprecated.Emits the "format-entry-text" signal. SeeonFormatEntryText(org.gnome.gtk.ComboBox.FormatEntryTextCallback)
. -
onMoveActive
public SignalConnection<ComboBox.MoveActiveCallback> onMoveActive(ComboBox.MoveActiveCallback handler) Deprecated.Emitted to move the active selection.This is an keybinding signal.
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitMoveActive
Deprecated.Emits the "move-active" signal. SeeonMoveActive(org.gnome.gtk.ComboBox.MoveActiveCallback)
. -
onPopdown
Deprecated.Emitted to popdown the combo box list.This is an keybinding signal.
The default bindings for this signal are Alt+Up and Escape.
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPopdown
public boolean emitPopdown()Deprecated.Emits the "popdown" signal. SeeonPopdown(org.gnome.gtk.ComboBox.PopdownCallback)
. -
onPopup
Deprecated.Emitted to popup the combo box list.This is an keybinding signal.
The default binding for this signal is Alt+Down.
- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitPopup
public void emitPopup()Deprecated.Emits the "popup" signal. SeeonPopup(org.gnome.gtk.ComboBox.PopupCallback)
. -
builder
Deprecated.AComboBox.Builder
object constructs aComboBox
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withComboBox.Builder.build()
.
-
DropDown