Class StringList

All Implemented Interfaces:
Iterable<StringObject>, Collection<StringObject>, List<StringObject>, SequencedCollection<StringObject>, ListModel<StringObject>, Buildable, Proxy, ListModelJavaList<StringObject>, ListModelJavaListMutable<StringObject>, ListModelJavaListSpliceable<StringObject>

@Generated("org.javagi.JavaGI") public class StringList extends GObject implements ListModel<StringObject>, Buildable, ListModelJavaListSpliceable<StringObject>

A list model that wraps an array of strings.

The objects in the model are of type StringObject and have a "string" property that can be used inside expressions.

GtkStringList is well-suited for any place where you would typically use a char*[], but need a list model.

GtkStringList as GtkBuildable

The GtkStringList implementation of the GtkBuildable interface supports adding items directly using the <items> element and specifying <item> elements for each item. Each <item> element supports the regular translation attributes “translatable”, “context” and “comments”.

Here is a UI definition fragment specifying a GtkStringList

<object class="GtkStringList">
  <items>
    <item translatable="yes">Factory</item>
    <item translatable="yes">Home</item>
    <item translatable="yes">Subway</item>
  </items>
</object>
  • Constructor Details

    • StringList

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

      public StringList(@Nullable String @Nullable [] strings)
      Creates a new GtkStringList with the given strings.
      Parameters:
      strings - The strings to put in the model
    • StringList

      public StringList()
      Create a new StringList.
  • Method Details

    • splice

      public void splice(int index, int nRemovals, Collection<? extends StringObject> additions)
      Modify this list by removing nRemovals elements starting at index and replacing them with the elements in additions.
      Specified by:
      splice in interface ListModelJavaListSpliceable<StringObject>
      Parameters:
      index - the index at which to splice the list
      nRemovals - the number of elements to remove
      additions - the elements to insert at the index
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • splice

      public void splice(int index, int nRemovals, StringObject[] additions)
      Modify this list by removing nRemovals elements starting at index and replacing them with the elements in additions.
      Specified by:
      splice in interface ListModelJavaListSpliceable<StringObject>
      Parameters:
      index - the index at which to splice the list
      nRemovals - the number of elements to remove
      additions - the elements to insert at the index
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • append

      public void append(StringObject e)
      Add the specified element to the end of the list.
      Specified by:
      append in interface ListModelJavaListMutable<StringObject>
      Parameters:
      e - element to be appended to the list
    • getType

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

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

      protected StringList asParent()
      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 GObject
      Returns:
      the instance as if it were its parent type
    • append

      public void append(String string)

      Appends string to self.

      The string will be copied. See take(String) for a way to avoid that.

      Parameters:
      string - the string to insert
    • find

      public int find(String string)

      Gets the position of the string in self.

      If this StringList does not contain string item, G_MAXUINT is returned.

      Parameters:
      string - the string to find
      Returns:
      the position of the string
      Since:
      4.18
    • getString

      public @Nullable String getString(int position)

      Gets the string that is at position in self.

      If this StringList does not contain position items, null is returned.

      This function returns the const char *. To get the object wrapping it, use g_list_model_get_item().

      Parameters:
      position - the position to get the string for
      Returns:
      the string at the given position
    • removeAt

      public void removeAt(int position)

      Removes the string at position from self.

      position must be smaller than the current length of the list.

      Specified by:
      removeAt in interface ListModelJavaListMutable<StringObject>
      Parameters:
      position - the position of the string that is to be removed
    • splice

      public void splice(int position, int nRemovals, @Nullable String @Nullable [] additions)

      Changes this StringList by removing nRemovals strings and adding additions to it.

      This function is more efficient than append(StringObject) and StringList.remove, because it only emits the ::items-changed signal once for the change.

      This function copies the strings in additions.

      The parameters position and nRemovals must be correct (ie: position + nRemovals must be less than or equal to the length of the list at the time this function is called).

      Parameters:
      position - the position at which to make the change
      nRemovals - the number of strings to remove
      additions - The strings to add
    • take

      public void take(String string)

      Adds string to self at the end, and takes ownership of it.

      This variant of append(StringObject) is convenient for formatting strings:

      gtk_string_list_take (self, g_strdup_print ("%d dollars", lots));
      
      Parameters:
      string - the string to insert
    • builder

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