Class ComboBoxText

All Implemented Interfaces:
PointerInterface

public class ComboBoxText extends ComboBox
A `GtkComboBoxText` is a simple variant of `GtkComboBox` for text-only
use cases.

![An example GtkComboBoxText](combo-box-text.png)

`GtkComboBoxText` hides the model-view complexity of `GtkComboBox`.

To create a `GtkComboBoxText`, use [ctor@Gtk.ComboBoxText.new] or
[ctor@Gtk.ComboBoxText.new_with_entry].

You can add items to a `GtkComboBoxText` with
[method@Gtk.ComboBoxText.append_text],
[method@Gtk.ComboBoxText.insert_text] or
[method@Gtk.ComboBoxText.prepend_text] and remove options with
[method@Gtk.ComboBoxText.remove].

If the `GtkComboBoxText` contains an entry (via the
[property@Gtk.ComboBox:has-entry] property), its contents can be retrieved
using [method@Gtk.ComboBoxText.get_active_text].

You should not call [method@Gtk.ComboBox.set_model] or attempt to pack more
cells into this combo box via its [iface@Gtk.CellLayout] interface.

# GtkComboBoxText as GtkBuildable

The `GtkComboBoxText` implementation of the `GtkBuildable` interface supports
adding items directly using the <items> element and specifying <item>
elements for each item. Each <item> element can specify the “id”
corresponding to the appended text and also supports the regular
translation attributes “translatable”, “context” and “comments”.

Here is a UI definition fragment specifying `GtkComboBoxText` items:
```xml
<object class="GtkComboBoxText">
<items>
<item translatable="yes" id="factory">Factory</item>
<item translatable="yes" id="home">Home</item>
<item translatable="yes" id="subway">Subway</item>
</items>
</object>
```

# CSS nodes

```
combobox
╰── box.linked
├── entry.combo
├── button.combo
╰── window.popup
```

`GtkComboBoxText` has a single CSS node with name combobox. It adds
the style class .combo to the main CSS nodes of its entry and button
children, and the .linked class to the node of its internal box.

https://docs.gtk.org/gtk4/class.ComboBoxText.html

  • Constructor Details

    • ComboBoxText

      public ComboBoxText(PointerContainer pointer)
    • ComboBoxText

      public ComboBoxText()
      Creates a new `GtkComboBoxText`.
  • Method Details

    • getClassHandler

      public static ClassHandler getClassHandler()
    • newWithEntryComboBoxText

      public static ComboBoxText newWithEntryComboBoxText()
      Creates a new `GtkComboBoxText` with an entry.
      Returns:
      a new `GtkComboBoxText`
    • append

      public void append(@Nullable Str id, @Nonnull Str text)
      Appends @text to the list of strings stored in @combo_box.

      If @id is non-%NULL then it is used as the ID of the row.

      This is the same as calling [method@Gtk.ComboBoxText.insert]
      with a position of -1.
      Parameters:
      id - a string ID for this value
      text - A string
    • append

      public void append(String id, String text)
      Appends @text to the list of strings stored in @combo_box.

      If @id is non-%NULL then it is used as the ID of the row.

      This is the same as calling [method@Gtk.ComboBoxText.insert]
      with a position of -1.
      Parameters:
      id - a string ID for this value
      text - A string
    • appendText

      public void appendText(@Nonnull Str text)
      Appends @text to the list of strings stored in @combo_box.

      This is the same as calling [method@Gtk.ComboBoxText.insert_text]
      with a position of -1.
      Parameters:
      text - A string
    • appendText

      public void appendText(String text)
      Appends @text to the list of strings stored in @combo_box.

      This is the same as calling [method@Gtk.ComboBoxText.insert_text]
      with a position of -1.
      Parameters:
      text - A string
    • getActiveText

      public Str getActiveText()
      Returns the currently active string in @combo_box.

      If no row is currently selected, %NULL is returned.
      If @combo_box contains an entry, this function will
      return its contents (which will not necessarily
      be an item from the list).
      Returns:
      a newly allocated string containing the currently active text. Must be freed with g_free().
    • insert

      public void insert(int position, @Nullable Str id, @Nonnull Str text)
      Inserts @text at @position in the list of strings stored in @combo_box.

      If @id is non-%NULL then it is used as the ID of the row.
      See [property@Gtk.ComboBox:id-column].

      If @position is negative then @text is appended.
      Parameters:
      position - An index to insert @text
      id - a string ID for this value
      text - A string to display
    • insert

      public void insert(int position, String id, String text)
      Inserts @text at @position in the list of strings stored in @combo_box.

      If @id is non-%NULL then it is used as the ID of the row.
      See [property@Gtk.ComboBox:id-column].

      If @position is negative then @text is appended.
      Parameters:
      position - An index to insert @text
      id - a string ID for this value
      text - A string to display
    • insertText

      public void insertText(int position, @Nonnull Str text)
      Inserts @text at @position in the list of strings stored in @combo_box.

      If @position is negative then @text is appended.

      This is the same as calling [method@Gtk.ComboBoxText.insert]
      with a %NULL ID string.
      Parameters:
      position - An index to insert @text
      text - A string
    • insertText

      public void insertText(int position, String text)
      Inserts @text at @position in the list of strings stored in @combo_box.

      If @position is negative then @text is appended.

      This is the same as calling [method@Gtk.ComboBoxText.insert]
      with a %NULL ID string.
      Parameters:
      position - An index to insert @text
      text - A string
    • prepend

      public void prepend(@Nullable Str id, @Nonnull Str text)
      Prepends @text to the list of strings stored in @combo_box.

      If @id is non-%NULL then it is used as the ID of the row.

      This is the same as calling [method@Gtk.ComboBoxText.insert]
      with a position of 0.
      Parameters:
      id - a string ID for this value
      text - a string
    • prepend

      public void prepend(String id, String text)
      Prepends @text to the list of strings stored in @combo_box.

      If @id is non-%NULL then it is used as the ID of the row.

      This is the same as calling [method@Gtk.ComboBoxText.insert]
      with a position of 0.
      Parameters:
      id - a string ID for this value
      text - a string
    • prependText

      public void prependText(@Nonnull Str text)
      Prepends @text to the list of strings stored in @combo_box.

      This is the same as calling [method@Gtk.ComboBoxText.insert_text]
      with a position of 0.
      Parameters:
      text - A string
    • prependText

      public void prependText(String text)
      Prepends @text to the list of strings stored in @combo_box.

      This is the same as calling [method@Gtk.ComboBoxText.insert_text]
      with a position of 0.
      Parameters:
      text - A string
    • remove

      public void remove(int position)
      Removes the string at @position from @combo_box.
      Parameters:
      position - Index of the item to remove
    • removeAll

      public void removeAll()
      Removes all the text entries from the combo box.
    • asAccessible

      public Accessible asAccessible()
      Implements interface Accessible. Call this to get access to interface functions.
      Overrides:
      asAccessible in class ComboBox
      Returns:
      Accessible
    • asBuildable

      public Buildable asBuildable()
      Implements interface Buildable. Call this to get access to interface functions.
      Overrides:
      asBuildable in class ComboBox
      Returns:
      Buildable
    • asCellEditable

      public CellEditable asCellEditable()
      Implements interface CellEditable. Call this to get access to interface functions.
      Overrides:
      asCellEditable in class ComboBox
      Returns:
      CellEditable
    • asCellLayout

      public CellLayout asCellLayout()
      Implements interface CellLayout. Call this to get access to interface functions.
      Overrides:
      asCellLayout in class ComboBox
      Returns:
      CellLayout
    • asConstraintTarget

      public ConstraintTarget asConstraintTarget()
      Implements interface ConstraintTarget. Call this to get access to interface functions.
      Overrides:
      asConstraintTarget in class ComboBox
      Returns:
      ConstraintTarget
    • getTypeID

      public static long getTypeID()
    • getParentTypeID

      public static long getParentTypeID()
    • getTypeSize

      public static TypeSystem.TypeSize getTypeSize()
    • getParentTypeSize

      public static TypeSystem.TypeSize getParentTypeSize()
    • getInstanceSize

      public static int getInstanceSize()