ListView

class ListView<T>(val items: MutableObservableList<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 fixedRowHeight. 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()
constructor(items: MutableObservableList<T>)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
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

Glok currently assumes that all rows are the same height. The easiest way to do this is settings fixedRowHeight. The default value is 0, in which case Glok looks at the size of the first visible row, and assumes the same is true for all the others. If this assumption is wrong, then scrolling will go wrong (it will jump weirdly).

Link copied to clipboard
Link copied to clipboard

If a mouse is clicked on a node, should it request the focus? For controls which can be read-only (such as TextArea / TextField), we may want to jump over them when pressing Tab (i.e. focusTraversable = false), but if they are clicked, then they should accept input focus. The user may wish to select, and copy part of the text.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The focus border is only ever drawn when the focus is set using keyboard shortcuts. So, when you use TAB or Shift+TAB, the extra focusBorder is drawn, but otherwise, it isn't drawn. This gives an uncluttered most of the time (when TAB isn't used).

Link copied to clipboard
Link copied to clipboard

The border is drawn OUTSIDE the bounds given by sceneX, sceneY ->width x height, and therefore doesn't add to the size of the Node. Nodes which are at the edge of the scene will have one (or two) edges missing.

Link copied to clipboard
Link copied to clipboard

true when this node has the input focus. Only 1 node has the input focus.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

A Background, which is drawn ON TOP of the node to highlight it. Used to highlight a section, when using the F6 and Shift+F6 keyboard shortcuts.

Link copied to clipboard
Link copied to clipboard

Is this part of the cycle of node that can accept keyboard focus when he user presses the Tab key (or Shift-Tab).

Link copied to clipboard
Link copied to clipboard

On a scale of 0..1, if this Node's parent has extra space compared to its preferred size, how much extra space should be give to this Node relative to its siblings?

Link copied to clipboard

The actual height of this node, in LogicalPixels.

Link copied to clipboard
Link copied to clipboard
var id: String
Link copied to clipboard

Supposedly unique identifier (or blank). However, it is up to the application developer to ensure the id is unique.

Link copied to clipboard
Link copied to clipboard

The position of this Node, relative to its parent Node in LogicalPixels. The position and size of Nodes are assigned by their parent in layout, using setChildBounds.

Link copied to clipboard
Link copied to clipboard

The position of this Node, relative to its parent Node in LogicalPixels. The position and size of Nodes are assigned by their parent in layout, using setChildBounds.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

A simple way to override the value calculated by nodeMinHeight. Most of the time, this value is null, and therefore nodeMinHeight is used.

Link copied to clipboard
Link copied to clipboard

A simple way to override the value calculated by nodeMinWidth. Most of the time, this value is null, and therefore nodeMinWidth is used.

Link copied to clipboard
Link copied to clipboard

A simple way to override the value calculated by nodePrefHeight. Most of the time, this value is null, and therefore nodePrefHeight is used.

Link copied to clipboard
Link copied to clipboard

A simple way to override the value calculated by nodeMinWidth. Most of the time, this value is null, and therefore nodeMinWidth is used.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var parent: Node?
Link copied to clipboard

Similar to styles, but used for temporary styles, such as :hover.

Link copied to clipboard
var scene: Scene?
Link copied to clipboard

An ObservableOptionalFont, whose value is Theme.defaultFont. To access this is quite convoluted, because both Node.scene and Scene.theme can change.

Link copied to clipboard

The X position of the Node relative to the top left of the window in LogicalPixels. The position and size of Nodes are assigned by their parent in layout, using setChildBounds.

Link copied to clipboard
Link copied to clipboard

The Y position of the Node relative to the top left of the window in LogicalPixels. The position and size of Nodes are assigned by their parent in layout, using setChildBounds.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

To help navigating a scene using keyboard shortcuts (not using a mouse), it is helpful to jump to different sections of the scene. The keyboard shortcut F6 is similar to TAB, but instead of moving one Node at a time, it jumps to the next node, where this is true. Shift+F6 navigates in the opposite direction.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

On a scale of 0..1, if this Node's parent has less space compared to its preferred size, how much should this node shrink by compared to its siblings.

Link copied to clipboard

Used by the Theme to determine how this node should be styled. Similar in concept to CSS's class attribute.

Link copied to clipboard
Link copied to clipboard

Defines a popup that appears when the user hover the mouse over this node for a period of time. Typically, containing help text and a KeyCombination.displayText (if this node can be activated using a keyboard shortcut).

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

When false, this node will not appear in the scene, and will not take up any spaces.

Link copied to clipboard

The actual width of this node, in LogicalPixels.

Link copied to clipboard

Functions

Link copied to clipboard
fun <E : Event> addEventFilter(eventType: EventType<E>, handler: EventHandler<E>, combination: HandlerCombination = HandlerCombination.AFTER)
fun <E : Event> addEventFilter(eventType: EventType<E>, handlerCombination: HandlerCombination = HandlerCombination.AFTER, handler: (E) -> Unit)
Link copied to clipboard
fun <E : Event> addEventHandler(eventType: EventType<E>, handler: EventHandler<E>, combination: HandlerCombination = HandlerCombination.AFTER)

fun <E : Event> addEventHandler(eventType: EventType<E>, combination: HandlerCombination = HandlerCombination.AFTER, handler: (E) -> Unit)
Link copied to clipboard
fun Region.borderSize(topBottom: Number, leftRight: Number)
fun Region.borderSize(top: Number, right: Number, bottom: Number, left: Number)
Link copied to clipboard
fun containsScenePoint(sceneX: Float, sceneY: Float): Boolean
Link copied to clipboard
fun dump(prefix: String = "", borders: Boolean = true, size: Boolean = true, filter: (Node) -> Boolean = { it.visible })

Dumps the scene graph to stdout starting at this Node, and walking through all descendants. Useful for debugging, and to give insights into the structure of controls.

Link copied to clipboard

Converts em units to LogicalPixels.

Link copied to clipboard

If overrideMaxHeight is set, then return that, otherwise return nodeMaxHeight. Caching is used to improve speed, as calculating sizes can be relatively expensive.

Link copied to clipboard

If overrideMaxWidth is set, then return that, otherwise return nodeMaxWidth. Caching is used to improve speed, as calculating sizes can be relatively expensive.

Link copied to clipboard

If overrideMinWidth is set, then return that, otherwise return nodeMinHeight. Caching is used to improve speed, as calculating sizes can be relatively expensive.

Link copied to clipboard

If overrideMinWidth is set, then return that, otherwise return nodeMinWidth. Caching is used to improve speed, as calculating sizes can be relatively expensive.

Link copied to clipboard

If overridePrefWidth is set, then return that, otherwise return nodePrefHeight. Caching is used to improve speed, as calculating sizes can be relatively expensive.

Link copied to clipboard

If overridePrefWidth is set, then return that, otherwise return nodePrefWidth. Caching is used to improve speed, as calculating sizes can be relatively expensive.

Link copied to clipboard
open fun findDeepestNodeAt(sceneX: Float, sceneY: Float): Node

@return this if none of my children are at sceneX,sceneY. Otherwise, the child (or one of its ancestors).

Link copied to clipboard

Checks this node, and all descendants for a matching id. @return The first node which matches, or null if none match.

Link copied to clipboard
open fun findStylableProperty(propertyName: String): StylableProperty<*>?
Link copied to clipboard
fun firstToRoot(filter: (Node) -> Boolean): Node?

Tests each node from this one to the root node. When filter hold true, that node is returned, stopping the iteration. If none are found, returns null.

Link copied to clipboard
fun forEachDescending(block: (Node) -> Unit)
Link copied to clipboard
fun forEachFromRoot(block: (Node) -> Unit)

Applies a block of code on this node, and all of its ancestors, starting at the root node and working downwards to this node.

Link copied to clipboard
fun forEachToRoot(block: (Node) -> Unit)

Applies a block of code on this node, and all of its ancestors, starting at this node and working up to the root node.

Link copied to clipboard
Link copied to clipboard
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

Return true, if other === this, or this is a parent, grandparent etc. of other.

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
Link copied to clipboard
Link copied to clipboard

Sets [Region.background to NoBackground

Link copied to clipboard
Link copied to clipboard
open fun nodeMaxHeight(): Float

The default implementation returns NO_MAXIMUM (an arbitrary large number : 100,000).

Link copied to clipboard
open fun nodeMaxWidth(): Float

The default implementation returns NO_MAXIMUM (an arbitrary large number : 100,000).

Link copied to clipboard
open fun nodeMinHeight(): Float

Each subclass should override this, to calculate the minimum height it requires. In general, do not call this, and instead call evalMinHeight.

Link copied to clipboard
open fun nodeMinWidth(): Float

Each subclass should override this to calculate the minimum width it requires. In general, do not call this, and instead call evalMinWidth.

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 onFilesDropped(combination: HandlerCombination = HandlerCombination.AFTER, handler: (DroppedFilesEvent) -> Unit)

A more convenient version of addEventHandler for EventType.FILES_DROPPED.

Link copied to clipboard
fun onKeyPressed(combination: HandlerCombination = HandlerCombination.AFTER, handler: (KeyEvent) -> Unit)

A more convenient version of addEventHandler for EventType.KEY_PRESSED.

Link copied to clipboard
fun onKeyReleased(combination: HandlerCombination = HandlerCombination.AFTER, handler: (KeyEvent) -> Unit)

A more convenient version of addEventHandler for EventType.KEY_RELEASED.

Link copied to clipboard
fun onKeyTyped(combination: HandlerCombination = HandlerCombination.AFTER, handler: (KeyTypedEvent) -> Unit)

A more convenient version of addEventHandler for EventType.KEY_TYPED.

Link copied to clipboard
fun onMouseClicked(combination: HandlerCombination = HandlerCombination.AFTER, handler: (MouseEvent) -> Unit)

A more convenient version of addEventHandler for EventType.MOUSE_CLICKED.

Link copied to clipboard
fun onMouseDragged(combination: HandlerCombination = HandlerCombination.AFTER, handler: (MouseEvent) -> Unit)

A more convenient version of addEventHandler for EventType.MOUSE_DRAGGED.

Link copied to clipboard
fun onMouseEntered(combination: HandlerCombination = HandlerCombination.AFTER, handler: (MouseEvent) -> Unit)

A more convenient version of addEventHandler for EventType.MOUSE_ENTERED.

Link copied to clipboard
fun onMouseExited(combination: HandlerCombination = HandlerCombination.AFTER, handler: (MouseEvent) -> Unit)

A more convenient version of addEventHandler for EventType.MOUSE_EXITED.

Link copied to clipboard
fun onMouseMoved(combination: HandlerCombination = HandlerCombination.AFTER, handler: (MouseEvent) -> Unit)

A more convenient version of addEventHandler for EventType.MOUSE_MOVED.

Link copied to clipboard
fun onMousePressed(combination: HandlerCombination = HandlerCombination.AFTER, handler: (MouseEvent) -> Unit)

A more convenient version of addEventHandler for EventType.MOUSE_PRESSED.

Link copied to clipboard
fun onMouseReleased(combination: HandlerCombination = HandlerCombination.AFTER, handler: (MouseEvent) -> Unit)

A more convenient version of addEventHandler for EventType.MOUSE_RELEASED.

Link copied to clipboard
fun onPopupTrigger(combination: HandlerCombination = HandlerCombination.AFTER, handler: (MouseEvent) -> Unit)

handler will fire when the secondary mouse button is pressed/released depending on the platform.

Link copied to clipboard
fun onScrolled(combination: HandlerCombination = HandlerCombination.AFTER, handler: (ScrollEvent) -> Unit)

A more convenient version of addEventHandler for EventType.SCROLL.

Link copied to clipboard
fun Region.padding(size: Number)
fun Region.padding(topBottom: Number, leftRight: Number)
fun Region.padding(top: Number, right: Number, bottom: Number, left: Number)
Link copied to clipboard
Link copied to clipboard
fun Region.plainBorder(color: Color, thickness: Number)
fun Region.plainBorder(color: Color, edges: Edges)
fun Region.plainBorder(color: Color, topBottom: Number, leftRight: Number)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Adds a style to Node.pseudoStyle

Link copied to clipboard
fun Node.pseudoStyleIf(test: Boolean, pseudoStyle: String)

Adds or removes the pseudoStyle depending on test. See Node.pseudoStyles

fun Node.pseudoStyleIf(test: Boolean, trueStyle: String, falseStyle: String)

When test is true, trueStyle is added, and falseStyle is removed from Node.pseudoStyles.

Link copied to clipboard
fun <E : Event> removeEventFilter(eventType: EventType<E>, handler: EventHandler<E>)
Link copied to clipboard
fun <E : Event> removeEventHandler(eventType: EventType<E>, handler: EventHandler<E>)
Link copied to clipboard
fun requestFocus(useFocusTraversable: Boolean = false, showFocusBorder: Boolean = false)

Gives the input focus to this node, so that keyboard events are sent to it.

Link copied to clipboard
open fun requestLayout()

Informs all ancestors that the pref/min/max size of this node has changed, and therefore layoutChildren needs to be called again before the scene is rendered. Cached data, such as prefWidth/height should be invalidated.

Link copied to clipboard

Informs that this node needs to be redrawn. Currently, this causes the whole scene to be redrawn.

Link copied to clipboard
Link copied to clipboard
fun Region.roundedBackground(color: String, radius: Number)
fun Region.roundedBackground(color: Color, radius: Number)
Link copied to clipboard
fun Region.roundedBorder(color: String, radius: Number)
fun Region.roundedBorder(color: Color, radius: Number)
fun Region.roundedBorder(color: String, radius: Number, thickness: Number)
fun Region.roundedBorder(color: Color, radius: Number, thickness: Number)
fun Region.roundedBorder(color: Color, radius: Number, edges: Edges)
fun Region.roundedBorder(color: Color, radius: Number, topBottom: Number, leftRight: Number)
Link copied to clipboard
fun scrollBy(delta: Float)
Link copied to clipboard
fun scrollTo()

Ensure that this node is visible, by asking all ancestor nodes, which are Scrollable, to scroll to this node. ScrollPanes will adjust their scroll bars, TabPanes will select the appropriate tab, TitledPanes will open their content etc.

Link copied to clipboard
fun scrollToItem(value: T)
Link copied to clipboard
fun scrollToRow(row: Int)
Link copied to clipboard
fun Node.style(name: String)

Adds a style to Node.styles

Link copied to clipboard
fun Node.styleIf(test: Boolean, style: String)

Adds or removes the style depending on test. See Node.styles

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun Region.thinBorder(color: Color)
Link copied to clipboard
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun treeVisitor(filter: (Node) -> Boolean = { true }, action: (Node) -> Unit)

Visits this node, and all descendant nodes, performing an action on each. Each node is filtered. If filter returns false, action will not be called on that node, and its children will not be visited.

Link copied to clipboard
fun Node.units(units: String): HBox
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun Node.withExpandBar(orientation: Orientation): Box

Adds a thin bar below this node. Dragging the bar changes the Node.overridePrefHeight of the node, therefore the node grows/shrinks.

Link copied to clipboard
Link copied to clipboard