Class ListView
- All Implemented Interfaces:
Proxy
,Accessible
,Buildable
,ConstraintTarget
,Orientable
,Scrollable
GtkListView
presents a large dynamic list of items.
GtkListView
uses its factory to generate one row widget for each visible
item and shows them in a linear display, either vertically or horizontally.
The Gtk.ListView:show-separators
property offers a simple way to
display separators between the rows.
GtkListView
allows the user to select items according to the selection
characteristics of the model. For models that allow multiple selected items,
it is possible to turn on _rubberband selection_, using
Gtk.ListView:enable-rubberband
.
If you need multiple columns with headers, see ColumnView
.
To learn more about the list widget framework, see the overview.
An example of using GtkListView
:
static void
setup_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
image = gtk_image_new ();
gtk_image_set_icon_size (GTK_IMAGE (image), GTK_ICON_SIZE_LARGE);
gtk_list_item_set_child (list_item, image);
}
static void
bind_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *image;
GAppInfo *app_info;
image = gtk_list_item_get_child (list_item);
app_info = gtk_list_item_get_item (list_item);
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
}
static void
activate_cb (GtkListView *list,
guint position,
gpointer unused)
{
GAppInfo *app_info;
app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
g_app_info_launch (app_info, NULL, NULL, NULL);
g_object_unref (app_info);
}
...
model = create_application_list ();
factory = gtk_signal_list_item_factory_new ();
g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL);
g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL);
list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory);
g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list);
Actions
GtkListView
defines a set of built-in actions:
list.activate-item
activates the item at given position by emitting theGtk.ListView::activate
signal.
CSS nodes
listview[.separators][.rich-list][.navigation-sidebar][.data-table]
├── row[.activatable]
│
├── row[.activatable]
│
┊
╰── [rubberband]
GtkListView
uses a single CSS node named listview
. It may carry the
.separators
style class, when Gtk.ListView:show-separators
property is set. Each child widget uses a single CSS node named row
.
If the Gtk.ListItem:activatable
property is set, the
corresponding row will have the .activatable
style class. For
rubberband selection, a node with name rubberband
is used.
The main listview node may also carry style classes to select the style of list presentation: .rich-list, .navigation-sidebar or .data-table.
Accessibility
GtkListView
uses the AccessibleRole.LIST
role, and the list
items use the AccessibleRole.LIST_ITEM
role.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface declaration of theActivateCallback
callback.static class
ListView.Builder<B extends ListView.Builder<B>>
Inner class implementing a builder pattern to construct a GObject with properties.static class
Nested classes/interfaces inherited from class org.gnome.gtk.ListBase
ListBase.ListBaseClass, ListBase.ListBaseImpl
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.ConstraintTarget
ConstraintTarget.ConstraintTargetImpl, ConstraintTarget.ConstraintTargetInterface
Nested classes/interfaces inherited from interface org.gnome.gtk.Orientable
Orientable.OrientableIface, Orientable.OrientableImpl
Nested classes/interfaces inherited from interface org.gnome.gtk.Scrollable
Scrollable.ScrollableImpl, Scrollable.ScrollableInterface
-
Constructor Summary
ConstructorDescriptionListView
(MemorySegment address) Create a ListView proxy instance for the provided memory address.ListView
(@Nullable SelectionModel model, @Nullable ListItemFactory factory) Creates a newGtkListView
that uses the givenfactory
for mapping items to widgets. -
Method Summary
Modifier and TypeMethodDescriptionprotected ListView
asParent()
Returns this instance as if it were its parent type.static ListView.Builder
<? extends ListView.Builder> builder()
AListView.Builder
object constructs aListView
with the specified properties.void
emitActivate
(int position) Emits the "activate" signal.boolean
Returns whether rows can be selected by dragging with the mouse.Gets the factory that's currently used to populate list items.Gets the factory that's currently used to populate section headers.getModel()
Gets the model that's currently used to read the items displayed.boolean
Returns whether the list box should show separators between rows.boolean
Returns whether rows will be activated on single click and selected on hover.Gets the behavior set for theTab
key.static Type
getType()
Get the GType of the ListView classonActivate
(ListView.ActivateCallback handler) Emitted when a row has been activated by the user, usually via activating the GtkListView|list.activate-item action.void
scrollTo
(int pos, Set<ListScrollFlags> flags, @Nullable ScrollInfo scroll) Scrolls to the item at the given position and performs the actions specified inflags
.void
scrollTo
(int pos, ListScrollFlags flags, @Nullable ScrollInfo scroll) Scrolls to the item at the given position and performs the actions specified inflags
.void
setEnableRubberband
(boolean enableRubberband) Sets whether selections can be changed by dragging with the mouse.void
setFactory
(@Nullable ListItemFactory factory) Sets theGtkListItemFactory
to use for populating list items.void
setHeaderFactory
(@Nullable ListItemFactory factory) Sets theGtkListItemFactory
to use for populating theListHeader
objects used in section headers.void
setModel
(@Nullable SelectionModel model) Sets the model to use.void
setShowSeparators
(boolean showSeparators) Sets whether the list box should show separators between rows.void
setSingleClickActivate
(boolean singleClickActivate) Sets whether rows should be activated on single click and selected on hover.void
setTabBehavior
(ListTabBehavior tabBehavior) Sets the behavior of theTab
andShift
+Tab
keys.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, getMemoryLayout, 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.Orientable
getOrientation, setOrientation
Methods inherited from interface org.gnome.gtk.Scrollable
getBorder, getHadjustment, getHscrollPolicy, getVadjustment, getVscrollPolicy, setHadjustment, setHscrollPolicy, setVadjustment, setVscrollPolicy
-
Constructor Details
-
ListView
Create a ListView proxy instance for the provided memory address.- Parameters:
address
- the memory address of the native object
-
ListView
public ListView(@Nullable @Nullable SelectionModel model, @Nullable @Nullable ListItemFactory factory) Creates a newGtkListView
that uses the givenfactory
for mapping items to widgets.The function takes ownership of the arguments, so you can write code like
list_view = gtk_list_view_new (create_model (), gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
- Parameters:
model
- the model to usefactory
- The factory to populate items with
-
-
Method Details
-
getType
-
asParent
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. -
getEnableRubberband
public boolean getEnableRubberband()Returns whether rows can be selected by dragging with the mouse.- Returns:
true
if rubberband selection is enabled
-
getFactory
Gets the factory that's currently used to populate list items.- Returns:
- The factory in use
-
getHeaderFactory
Gets the factory that's currently used to populate section headers.- Returns:
- The factory in use
-
getModel
Gets the model that's currently used to read the items displayed.- Returns:
- The model in use
-
getShowSeparators
public boolean getShowSeparators()Returns whether the list box should show separators between rows.- Returns:
true
if the list box shows separators
-
getSingleClickActivate
public boolean getSingleClickActivate()Returns whether rows will be activated on single click and selected on hover.- Returns:
true
if rows are activated on single click
-
getTabBehavior
Gets the behavior set for theTab
key.- Returns:
- The behavior of the
Tab
key
-
scrollTo
Scrolls to the item at the given position and performs the actions specified inflags
.This function works no matter if the listview is shown or focused. If it isn't, then the changes will take effect once that happens.
- Parameters:
pos
- position of the item. Must be less than the number of items in the view.flags
- actions to performscroll
- details of how to perform the scroll operation ornull
to scroll into view
-
scrollTo
Scrolls to the item at the given position and performs the actions specified inflags
.This function works no matter if the listview is shown or focused. If it isn't, then the changes will take effect once that happens.
- Parameters:
pos
- position of the item. Must be less than the number of items in the view.flags
- actions to performscroll
- details of how to perform the scroll operation ornull
to scroll into view
-
setEnableRubberband
public void setEnableRubberband(boolean enableRubberband) Sets whether selections can be changed by dragging with the mouse.- Parameters:
enableRubberband
-true
to enable rubberband selection
-
setFactory
Sets theGtkListItemFactory
to use for populating list items.- Parameters:
factory
- the factory to use
-
setHeaderFactory
Sets theGtkListItemFactory
to use for populating theListHeader
objects used in section headers.If this factory is set to
null
, the list will not show section headers.- Parameters:
factory
- the factory to use
-
setModel
Sets the model to use.This must be a
SelectionModel
to use.- Parameters:
model
- the model to use
-
setShowSeparators
public void setShowSeparators(boolean showSeparators) Sets whether the list box should show separators between rows.- Parameters:
showSeparators
-true
to show separators
-
setSingleClickActivate
public void setSingleClickActivate(boolean singleClickActivate) Sets whether rows should be activated on single click and selected on hover.- Parameters:
singleClickActivate
-true
to activate items on single click
-
setTabBehavior
Sets the behavior of theTab
andShift
+Tab
keys.- Parameters:
tabBehavior
- The desired tab behavior
-
onActivate
Emitted when a row has been activated by the user, usually via activating the GtkListView|list.activate-item action.This allows for a convenient way to handle activation in a listview. See
ListItem.setActivatable(boolean)
for details on how to use this signal.- Parameters:
handler
- the signal handler- Returns:
- a signal handler ID to keep track of the signal connection
- See Also:
-
emitActivate
public void emitActivate(int position) Emits the "activate" signal. SeeonActivate(org.gnome.gtk.ListView.ActivateCallback)
. -
builder
AListView.Builder
object constructs aListView
with the specified properties. Use the variousset...()
methods to set properties, and finish construction withListView.Builder.build()
.
-