Class ComboBox

All Implemented Interfaces:
Accessible, Buildable, CellEditable, CellLayout, ConstraintTarget, Proxy
Direct Known Subclasses:
ComboBoxText

@Generated("org.javagi.JavaGI") @Deprecated public class ComboBox extends Widget implements Accessible, Buildable, CellEditable, CellLayout, ConstraintTarget
Deprecated.
Use DropDown instead

A GtkComboBox is a widget that allows the user to choose from a list of valid choices.

An example GtkComboBox

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.

  • Constructor Details

    • ComboBox

      public ComboBox(MemorySegment address)
      Deprecated.
      Create a ComboBox instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • ComboBox

      public ComboBox()
      Deprecated.
      Create a new ComboBox.
  • Method Details

    • getType

      public static @Nullable Type getType()
      Deprecated.
      Get the GType of the ComboBox class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      Deprecated.
      The memory layout of the native struct.
      Returns:
      the memory layout
    • asParent

      protected ComboBox asParent()
      Deprecated.
      Return this instance as if it were its parent type. Comparable to the Java super keyword, but ensures the parent typeclass is also used in native code.
      Overrides:
      asParent in class Widget
      Returns:
      the instance as if it were its parent type
    • withEntry

      @Deprecated public static ComboBox withEntry()
      Deprecated.

      Creates a new empty GtkComboBox 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 public static ComboBox withModel(TreeModel model)
      Deprecated.
      Creates a new GtkComboBox with a model.
      Parameters:
      model - a GtkTreeModel
      Returns:
      A new GtkComboBox
    • withModelAndEntry

      @Deprecated public static ComboBox withModelAndEntry(TreeModel model)
      Deprecated.

      Creates a new empty GtkComboBox with an entry and a model.

      See also withEntry().

      Parameters:
      model - A GtkTreeModel
      Returns:
      A new GtkComboBox
    • getActive

      @Deprecated public int getActive()
      Deprecated.

      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], where path is the Gtk.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 public @Nullable String getActiveId()
      Deprecated.

      Returns the ID of the active row of comboBox.

      This value is taken from the active row and the column specified by the Gtk.ComboBox:id-column property of this ComboBox (see setIdColumn(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 a null ID value, then null is returned.

      Returns:
      the ID of the active row
    • getActiveIter

      @Deprecated public boolean getActiveIter(TreeIter iter)
      Deprecated.

      Sets iter to point to the currently active item.

      If no item is active, iter is left unchanged.

      Parameters:
      iter - A GtkTreeIter
      Returns:
      true if iter was set, false otherwise
    • getButtonSensitivity

      @Deprecated public SensitivityType getButtonSensitivity()
      Deprecated.
      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 or SensitivityType.AUTO if it is only sensitive as long as the model has one item to be selected.
    • getChild

      @Deprecated public @Nullable Widget getChild()
      Deprecated.
      Gets the child widget of comboBox.
      Returns:
      the child widget of this ComboBox
    • getEntryTextColumn

      @Deprecated public int getEntryTextColumn()
      Deprecated.
      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 comboBox.
    • getHasEntry

      @Deprecated public boolean getHasEntry()
      Deprecated.
      Returns whether the combo box has an entry.
      Returns:
      whether there is an entry in comboBox.
    • getIdColumn

      @Deprecated public int getIdColumn()
      Deprecated.
      Returns 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 public @Nullable TreeModel getModel()
      Deprecated.
      Returns the GtkTreeModel of comboBox.
      Returns:
      A GtkTreeModel which was passed during construction.
    • getPopupFixedWidth

      @Deprecated public boolean getPopupFixedWidth()
      Deprecated.
      Gets whether the popup uses a fixed width.
      Returns:
      true if the popup uses a fixed width
    • getRowSeparatorFunc

      @Deprecated public @Nullable TreeViewRowSeparatorFunc getRowSeparatorFunc()
      Deprecated.
      Returns the current row separator function.
      Returns:
      the current row separator function.
    • popdown

      @Deprecated public void popdown()
      Deprecated.

      Hides the menu or dropdown list of comboBox.

      This function is mostly intended for use by accessibility technologies; applications should have little use for it.

    • popup

      @Deprecated public void popup()
      Deprecated.

      Pops up the menu or dropdown list of 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 public void popupForDevice(Device device)
      Deprecated.

      Pops up the menu of 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 - a GdkDevice
    • setActive

      @Deprecated public void setActive(int index)
      Deprecated.
      Sets the active item of this ComboBox to be the item at index.
      Parameters:
      index - An index in the model passed during construction, or -1 to have no active item
    • setActiveId

      @Deprecated public boolean setActiveId(@Nullable String activeId)
      Deprecated.

      Changes the active row of this ComboBox to the one that has an ID equal to activeId.

      If activeId is null, the active row is unset. Rows having a null 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 returns false.

      Parameters:
      activeId - the ID of the row to select
      Returns:
      true if a row with a matching ID was found. If a null activeId was given to unset the active row, the function always returns true.
    • setActiveIter

      @Deprecated public void setActiveIter(@Nullable TreeIter iter)
      Deprecated.

      Sets the current active item to be the one referenced by iter.

      If iter is null, the active item is unset.

      Parameters:
      iter - The GtkTreeIter
    • setButtonSensitivity

      @Deprecated public void setButtonSensitivity(SensitivityType sensitivity)
      Deprecated.
      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 public void setChild(@Nullable Widget child)
      Deprecated.
      Sets the child widget of comboBox.
      Parameters:
      child - the child widget
    • setEntryTextColumn

      @Deprecated public void setEntryTextColumn(int textColumn)
      Deprecated.

      Sets the model column which this ComboBox should use to get strings from to be textColumn.

      For this column no separate CellRenderer is needed.

      The column textColumn in the model of this ComboBox must be of type G_TYPE_STRING.

      This is only relevant if this ComboBox has been created with Gtk.ComboBox:has-entry as true.

      Parameters:
      textColumn - A column in model to get the strings from for the internal entry
    • setIdColumn

      @Deprecated public void setIdColumn(int idColumn)
      Deprecated.

      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 type G_TYPE_STRING.

      Parameters:
      idColumn - A column in model to get string IDs for values from
    • setModel

      @Deprecated public void setModel(@Nullable TreeModel model)
      Deprecated.

      Sets the model used by this ComboBox to be model.

      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 - A GtkTreeModel
    • setPopupFixedWidth

      @Deprecated public void setPopupFixedWidth(boolean fixed)
      Deprecated.

      Specifies whether the popup’s width should be a fixed width.

      If fixed is true, 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 public void setRowSeparatorFunc(@Nullable TreeViewRowSeparatorFunc func)
      Deprecated.

      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 - a GtkTreeViewRowSeparatorFunc
    • activate

      protected void activate()
      Deprecated.
    • changed

      protected void changed()
      Deprecated.
      Signal is emitted when the active item is changed.
    • formatEntryText

      protected String formatEntryText(String path)
      Deprecated.
      Signal which allows you to change how the text displayed in a combo box’s entry is displayed.
    • onActivate

      Deprecated.

      Emitted to when the combo box is activated.

      The ::activate signal on GtkComboBox 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
      Since:
      4.6
      See Also:
    • emitActivate

      public void emitActivate()
      Deprecated.
      Emits the "activate" signal. See onActivate(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(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. See onChanged(ComboBox.ChangedCallback).
    • onFormatEntryText

      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 the Gtk.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

      public String emitFormatEntryText(String path)
      Deprecated.
      Emits the "format-entry-text" signal. See onFormatEntryText(ComboBox.FormatEntryTextCallback).
    • onMoveActive

      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

      public void emitMoveActive(ScrollType scrollType)
      Deprecated.
      Emits the "move-active" signal. See onMoveActive(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. See onPopdown(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. See onPopup(ComboBox.PopupCallback).
    • builder

      public static ComboBox.Builder<? extends ComboBox.Builder> builder()
      Deprecated.
      A ComboBox.Builder object constructs a ComboBox with the specified properties. Use the various set...() methods to set properties, and finish construction with ComboBox.Builder.build().
      Returns:
      the builder object