Class ComboBox
- All Implemented Interfaces:
Accessible,Buildable,CellEditable,CellLayout,ConstraintTarget,Proxy
- 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 Gtk.AccessibleRole.combo_box role.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated.Functional interface declaration of theActivateCallbackcallback.static classComboBox.Builder<B extends ComboBox.Builder<B>>Deprecated.Inner class implementing a builder pattern to construct a GObject with properties.static interfaceDeprecated.Functional interface declaration of theChangedCallbackcallback.static classDeprecated.static interfaceDeprecated.Functional interface declaration of theFormatEntryTextCallbackcallback.static interfaceDeprecated.Functional interface declaration of theMoveActiveCallbackcallback.static interfaceDeprecated.Functional interface declaration of thePopdownCallbackcallback.static interfaceDeprecated.Functional interface declaration of thePopupCallbackcallback.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.Buildable
Buildable.Buildable$Impl, Buildable.BuildableIfaceNested classes/interfaces inherited from interface org.gnome.gtk.CellEditable
CellEditable.CellEditable$Impl, CellEditable.CellEditableIface, CellEditable.EditingDoneCallback, CellEditable.RemoveWidgetCallbackNested classes/interfaces inherited from interface org.gnome.gtk.CellLayout
CellLayout.CellLayout$Impl, CellLayout.CellLayoutIfaceNested classes/interfaces inherited from interface org.gnome.gtk.ConstraintTarget
ConstraintTarget.ConstraintTarget$Impl, ConstraintTarget.ConstraintTargetInterface -
Constructor Summary
ConstructorsConstructorDescriptionComboBox()Deprecated.Creates a new ComboBox.ComboBox(MemorySegment address) Deprecated.Create a ComboBox proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidactivate()Deprecated.protected ComboBoxasParent()Deprecated.Returns this instance as if it were its parent type.static ComboBox.Builder<? extends ComboBox.Builder> builder()Deprecated.AComboBox.Builderobject constructs aComboBoxwith the specified properties.protected voidchanged()Deprecated.Signal is emitted when the active item is changed.voidDeprecated.Emits the "activate" signal.voidDeprecated.Emits the "changed" signal.emitFormatEntryText(String path) Deprecated.Emits the "format-entry-text" signal.voidemitMoveActive(ScrollType scrollType) Deprecated.Emits the "move-active" signal.booleanDeprecated.Emits the "popdown" signal.voidDeprecated.Emits the "popup" signal.protected StringformatEntryText(String path) Deprecated.Signal which allows you to change how the text displayed in a combo box’s entry is displayed.intDeprecated.UseDropDown@Nullable StringDeprecated.UseDropDownbooleangetActiveIter(TreeIter iter) Deprecated.UseDropDownDeprecated.UseDropDown@Nullable WidgetgetChild()Deprecated.UseDropDownintDeprecated.UseDropDownbooleanDeprecated.UseDropDownintDeprecated.UseDropDownstatic MemoryLayoutDeprecated.The memory layout of the native struct.@Nullable TreeModelgetModel()Deprecated.UseDropDownbooleanDeprecated.UseDropDown@Nullable TreeViewRowSeparatorFuncDeprecated.UseDropDownstatic @Nullable TypegetType()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.voidpopdown()Deprecated.UseDropDownvoidpopup()Deprecated.UseDropDownvoidpopupForDevice(Device device) Deprecated.UseDropDownvoidsetActive(int index) Deprecated.UseDropDownbooleansetActiveId(@Nullable String activeId) Deprecated.UseDropDownvoidsetActiveIter(@Nullable TreeIter iter) Deprecated.UseDropDownvoidsetButtonSensitivity(SensitivityType sensitivity) Deprecated.UseDropDownvoidDeprecated.UseDropDownvoidsetEntryTextColumn(int textColumn) Deprecated.UseDropDownvoidsetIdColumn(int idColumn) Deprecated.UseDropDownvoidDeprecated.UseDropDownvoidsetPopupFixedWidth(boolean fixed) Deprecated.UseDropDownvoidsetRowSeparatorFunc(@Nullable TreeViewRowSeparatorFunc func) Deprecated.UseDropDownstatic ComboBoxDeprecated.UseDropDownstatic ComboBoxDeprecated.UseDropDownstatic ComboBoxwithModelAndEntry(TreeModel model) Deprecated.UseDropDownMethods 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.Buildable
getBuildableIdMethods inherited from interface org.gnome.gtk.CellEditable
editingDone, emitEditingDone, emitRemoveWidget, onEditingDone, onRemoveWidget, removeWidget, startEditingMethods 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
public ComboBox()Deprecated.Creates a new ComboBox.
-
-
Method Details
-
getType
Deprecated.Get the GType of the ComboBox class- Returns:
- the GType
-
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 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. -
withEntry
Deprecated.UseDropDownCreates a new emptyGtkComboBoxwith 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.UseDropDownCreates a newGtkComboBoxwith a model.- Parameters:
model- aGtkTreeModel- Returns:
- A new
GtkComboBox
-
withModelAndEntry
Deprecated.UseDropDownCreates a new emptyGtkComboBoxwith an entry and a model.See also
withEntry().- Parameters:
model- AGtkTreeModel- Returns:
- A new
GtkComboBox
-
getActive
Deprecated.UseDropDownReturns 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], wherepathis theGtk.TreePathof 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.UseDropDownReturns the ID of the active row ofcomboBox.This value is taken from the active row and the column specified by the
Gtk.ComboBox:id-columnproperty 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-columnproperty of this ComboBox is not set, or if no row is active, or if the active row has anullID value, thennullis returned.- Returns:
- the ID of the active row
-
getActiveIter
Deprecated.UseDropDownSetsiterto point to the currently active item.If no item is active,
iteris left unchanged.- Parameters:
iter- AGtkTreeIter- Returns:
trueifiterwas set,falseotherwise
-
getButtonSensitivity
Deprecated.UseDropDownReturns whether the combo box sets the dropdown button sensitive or not when there are no items in the model.- Returns:
SensitivityType.ONif the dropdown button is sensitive when the model is empty,SensitivityType.OFFif the button is always insensitive orSensitivityType.AUTOif it is only sensitive as long as the model has one item to be selected.
-
getChild
Deprecated.UseDropDownGets the child widget ofcomboBox.- Returns:
- the child widget of this ComboBox
-
getEntryTextColumn
Deprecated.UseDropDownReturns 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
comboBox.
-
getHasEntry
Deprecated.UseDropDownReturns whether the combo box has an entry.- Returns:
- whether there is an entry in
comboBox.
-
getIdColumn
Deprecated.UseDropDownReturns the column which this ComboBox is using to get string IDs for values from.- Returns:
- A column in the data source model of
comboBox.
-
getModel
Deprecated.UseDropDownReturns theGtkTreeModelofcomboBox.- Returns:
- A
GtkTreeModelwhich was passed during construction.
-
getPopupFixedWidth
Deprecated.UseDropDownGets whether the popup uses a fixed width.- Returns:
trueif the popup uses a fixed width
-
getRowSeparatorFunc
Deprecated.UseDropDownReturns the current row separator function.- Returns:
- the current row separator function.
-
popdown
Deprecated.UseDropDownHides the menu or dropdown list ofcomboBox.This function is mostly intended for use by accessibility technologies; applications should have little use for it.
-
popup
Deprecated.UseDropDownPops up the menu or dropdown list ofcomboBox.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.UseDropDownPops up the menu ofcomboBox.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.UseDropDownSets 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.UseDropDownChanges the active row of this ComboBox to the one that has an ID equal toactiveId.If
activeIdisnull, the active row is unset. Rows having anullID string cannot be made active by this function.If the
Gtk.ComboBox:id-columnproperty 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:
trueif a row with a matching ID was found. If anullactiveIdwas given to unset the active row, the function always returnstrue.
-
setActiveIter
Deprecated.UseDropDownSets the current active item to be the one referenced byiter.If
iterisnull, the active item is unset.- Parameters:
iter- TheGtkTreeIter
-
setButtonSensitivity
Deprecated.UseDropDownSets 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
-
setEntryTextColumn
Deprecated.UseDropDownSets the model column which this ComboBox should use to get strings from to betextColumn.For this column no separate
CellRendereris needed.The column
textColumnin 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-entryastrue.- Parameters:
textColumn- A column inmodelto get the strings from for the internal entry
-
setIdColumn
Deprecated.UseDropDownSets the model column which this ComboBox should use to get string IDs for values from.The column
idColumnin the model of this ComboBox must be of typeG_TYPE_STRING.- Parameters:
idColumn- A column inmodelto get string IDs for values from
-
setModel
Deprecated.UseDropDownSets 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.UseDropDownSpecifies whether the popup’s width should be a fixed width.If
fixedistrue, 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.UseDropDownSets 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
::activatesignal onGtkComboBoxis 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
- Since:
- 4.6
- 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-columnmodel 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.Builderobject constructs aComboBoxwith the specified properties. Use the variousset...()methods to set properties, and finish construction withComboBox.Builder.build().- Returns:
- the builder object
-
DropDowninstead