ListView

class ListView<T> : Region

Displays a list of items vertically inside a ScrollPane.

Each visible item in the list is displayed using a ListCell. By default, cellFactory creates TextListCells, whose text is each items value converted to a string using Any.toString. However, you can create a custom cellFactory, which creates any ListCells containing whatever you need.

There are only ever enough ListCells for the visible items. For example, if items.size == 100, but only 10 fit within the ListView's bounds, then there be 10 ListCells, and as you scroll, the same 10 ListCells will be reused, and their contents will be updated to reflect the data within the items.

If type T is mutable, then the cellFactory must bind to the item's properties, to ensure that mutating the data is reflected in the ListCell.

Currently, all cells must be the same height, which is governed by fixedCellSize. and if this is <= 0, then the first cell's prefHeight is used instead.

Theme DSL

"list_view" {
    "fixedCellSize"( float )

    descendant("list_cell") {
        ":odd" { ... }
        ":even" { ... }
        // The selected row of the listView.
        ":selected" { ... }
    }
}

Constructors

Link copied to clipboard
constructor()

Properties

Link copied to clipboard
Link copied to clipboard

When set, items in the ListView can be reordered by dragging with the mouse, and also using Ctrl+Up / Down. The default value is false.

Link copied to clipboard

A ListView has a list of ListCells for the items which are visible. The ListCells are created and destroyed as you scroll through the list.

Link copied to clipboard
open override val children: ObservableList<ScrollPane>

The base class Node has no children, so this is an empty list.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var value: T?
Link copied to clipboard

Functions

Link copied to clipboard
fun indexOf(value: T): Int

Find the index of value within items, using === as the test. This is different from List.indexOf, which uses equals() rather than ===. Therefore List.indexOf would find the wrong item if there are more than one item in the list that met the equals() test.

Link copied to clipboard
fun moveItem(oldIndex: Int, newIndex: Int)

Moves an item within items. If the item was previously selected, it remains selected. (If you were to just remove and add the item, this would not be true).

Link copied to clipboard
open override fun nodePrefHeight(): Float

By default, ListViews have an arbitrary prefHeight. Set evalPrefHeight, or add the ListView to a layout control which will allocate a sensible area regardless of evalPrefWidth.

Link copied to clipboard
open override fun nodePrefWidth(): Float

By default, ListViews have an arbitrary prefWidth. Set evalPrefWidth, or add the ListView to a layout control which will allocate a sensible area regardless of evalPrefWidth.

Link copied to clipboard
fun scrollBy(delta: Float)
Link copied to clipboard
fun scrollToItem(value: T)
Link copied to clipboard
fun scrollToRow(row: Int)
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard