Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: ListView

[113:7] extends: Control

The ListView class wraps the JavaFX ListView control, which displays a scrollable list of items where the user can select one or more entries. Items are provided as an ObservableList and the control automatically reflects any changes made to that list. ListView supports both horizontal and vertical orientations, single or multiple selection modes, and selection-change listeners for responding to user interaction. The tables below list every CSS property available to ListView, organized by the class level where each property is defined.

CSS Pseudo-classes -- ListView

Pseudo-class Description
horizontal Applies when the orientation is horizontal.
vertical Applies when the orientation is vertical.

CSS Properties -- ListView

Property Values Default Description
-fx-orientation horizontal | vertical vertical Axis along which list items are arranged.

CSS Properties -- Control

Property Values Default Description
-fx-skin <string> null Fully qualified class name of the Skin to use for rendering this control.
-fx-focus-traversable true | false true When true, the control participates in focus traversal via the keyboard Tab key. (Default is false for Accordion, ScrollPane.)

CSS Properties -- Region

Background fills

Property Values Default Description
-fx-background-color <paint> [, <paint>]* transparent One or more paint values for background fill layers, rendered back to front.
-fx-background-insets <size> or <t> <r> <b> <l> [, ...]* 0 0 0 0 Insets from the region edges for each background fill layer.
-fx-background-radius <size> [/ <size>]* [, ...]* 0 0 0 0 Corner radii for each background fill layer.

Background images

Property Values Default Description
-fx-background-image <uri> [, <uri>]* null One or more image URIs for background image layers.
-fx-background-position <bg-position> [, ...]* 0% 0% Position of each background image within the region. Accepts keywords or size values.
-fx-background-repeat <repeat-style> [, ...]* repeat repeat Tiling behavior for each background image. Values: repeat, no-repeat, round, space applied per axis.
-fx-background-size <bg-size> [, ...]* auto auto Dimensions for each background image. Supports cover, contain, stretch, or explicit sizes.

Stroked borders

Property Values Default Description
-fx-border-color <paint> or <t> <r> <b> <l> [, ...]* null Paint colors for the border stroke layers.
-fx-border-insets <size> or <t> <r> <b> <l> [, ...]* null Insets from region edges for each border layer.
-fx-border-radius <size> [, ...]* null Corner radii for border stroke layers.
-fx-border-style <border-style> [, ...]* null Border line style (solid, dotted, dashed) plus phase and line cap/join options per layer.
-fx-border-width <size> or <t> <r> <b> <l> [, ...]* null Thickness of each border stroke layer, per side.

Border images

Property Values Default Description
-fx-border-image-source <uri> [, <uri>]* null Image URIs used to paint the border.
-fx-border-image-insets <size> or <t> <r> <b> <l> [, ...]* 0 0 0 0 Insets for each border image layer.
-fx-border-image-repeat <repeat-style> [, ...]* repeat repeat Tiling behavior for each border image.
-fx-border-image-slice <size> or <t> <r> <b> <l> [fill] [, ...]* 100% Divides each border image into nine regions. Adding fill preserves the center region.
-fx-border-image-width <size> or <t> <r> <b> <l> [, ...]* 1 1 1 1 Width of each border image slice per side.

Other Region properties

Property Values Default Description
-fx-padding <size> or <t> <r> <b> <l> 0 0 0 0 Interior padding between the region border and its content.
-fx-shape <string> null SVG path string that defines a custom clip shape for the region.
-fx-scale-shape true | false true When true, the shape is scaled to fit the region.
-fx-position-shape true | false true When true, the shape is centered within the region.
-fx-snap-to-pixel true | false true When true, positions and sizes are rounded to whole pixel boundaries.
-fx-min-width <size> -1 Minimum width. -1 uses the computed minimum.
-fx-pref-width <size> -1 Preferred width. -1 uses the computed preferred.
-fx-max-width <size> -1 Maximum width. -1 uses the computed maximum.
-fx-min-height <size> -1 Minimum height. -1 uses the computed minimum.
-fx-pref-height <size> -1 Preferred height. -1 uses the computed preferred.
-fx-max-height <size> -1 Maximum height. -1 uses the computed maximum.

CSS Properties -- Node

Property Values Default Description
-fx-blend-mode add | blue | color-burn | color-dodge | darken | difference | exclusion | green | hard-light | lighten | multiply | overlay | red | screen | soft-light | src-atop | src-in | src-out | src-over null Blend mode used when compositing this node with nodes beneath it.
-fx-cursor null | crosshair | default | hand | move | e-resize | h-resize | ne-resize | nw-resize | n-resize | se-resize | sw-resize | s-resize | w-resize | v-resize | text | wait | <url> null (inherits) Mouse cursor shape shown when the pointer is over this node. Inherits from parent by default.
-fx-effect <effect> null A visual effect (e.g. DropShadow, InnerShadow) applied to the rendered node.
-fx-focus-traversable true | false false Whether this node participates in focus traversal. Overridden to true by Control.
-fx-view-order <number> 0 Adjusts rendering and hit-test order within the parent without changing the scene graph order.
-fx-opacity <number> [0.0 - 1.0] 1 Opacity of the node. 0 is fully transparent, 1 is fully opaque.
-fx-rotate <number> 0 Rotation angle in degrees applied around the node's center point. Positive values are clockwise.
-fx-scale-x <number> 1 Scale factor along the X axis about the node's center.
-fx-scale-y <number> 1 Scale factor along the Y axis about the node's center.
-fx-scale-z <number> 1 Scale factor along the Z axis about the node's center.
-fx-translate-x <number> 0 Translation offset along the X axis in pixels.
-fx-translate-y <number> 0 Translation offset along the Y axis in pixels.
-fx-translate-z <number> 0 Translation offset along the Z axis in pixels.
visibility visible | hidden | collapse | inherit visible Controls whether the node is rendered and participates in layout. collapse removes it from layout; hidden keeps the space.
-fx-managed true | false true When false, the parent layout does not manage this node's position or size.

Methods

  • ListView (Items = null)

    Initializes a new ListView instance with optional items. If an item list is provided, it is set as the initial content of the ListView.

    • @p Items An array of items to populate the ListView, or null for an empty list.
    • @r this object
  • onChange (callback OnChange)

    Sets a callback function that triggers when the selected item changes.

    • @p OnChange The callback function to execute on item selection change.
    • @r this object for chaining
  • getSelected ()

    Retrieves the currently selected item in the ListView.

    • @r The selected item object, or null if no item is selected.
  • setItems (list Items)

    Sets the list of items to display in the ListView.

    • @p Items is a list of items to set as the ListView content.
    • @r this object
  • getItems ()

    Returns the list of items currently in the ListView.

    • @r A list with the current items.
  • getSelectedIndex ()

    Returns the index of the currently selected item.

    • @r An int with the selected index, or -1 if nothing is selected.
  • setOrientation (string Orientation)

    Sets the orientation of the ListView.

    • @p Orientation is a string: HORIZONTAL or VERTICAL.
    • @r this object
  • setPrefSize (double Width, double Height)

    Sets the preferred width and height of the ListView.

    • @p Width is a double with the preferred width in pixels.
    • @p Height is a double with the preferred height in pixels.
    • @r this object
  • setCellFactory (callback Factory)

    Sets a custom cell factory callback that creates cells for each item.

    • @p Factory is a callback that receives a ListView and returns a ListCell.
    • @r this object
  • setId (string Id)

    Sets the CSS id of this ListView node.

    • @p Id is a string with the CSS id.
    • @r this object
  • setStyle (string Style)

    Sets the inline CSS style string for this ListView.

    • @p Style is a string with the CSS style rules.
    • @r this object
  • setSelectionMode (string Mode)

    Sets the selection mode for the ListView.

    • @p Mode is a string: SINGLE or MULTIPLE.
    • @r this object
  • setPlaceholder (object NodeObj)

    Sets a placeholder node to display when the ListView has no items.

    • @p NodeObj is a Node object to use as the placeholder.
    • @r this object
  • getSelectionModel ()

    Internal method to get the selection model for the ListView.

    • @r The selection model for managing item selection.
  • itemsProperty ()

    Returns the property holding the items list.

    • @r An ObjectProperty AJO holding the items ObservableList.
  • placeholderProperty ()

    Returns the property holding the placeholder node.

    • @r An ObjectProperty AJO holding the placeholder Node.
  • getPlaceholder ()

    Returns the placeholder node shown when the ListView has no items.

    • @r An AJO holding the placeholder Node, or null when none is set.
  • setSelectionModelAjo (object ModelObj)

    Sets the selection model used by this ListView.

    • @p ModelObj is the MultipleSelectionModel AJO to use.
    • @r this object
  • getSelectionModelAjo ()

    Returns the selection model used by this ListView.

    • @r An AJO holding the MultipleSelectionModel.
  • selectionModelProperty ()

    Returns the property holding the selection model.

    • @r An ObjectProperty AJO holding the MultipleSelectionModel.
  • setFocusModel (object ModelObj)

    Sets the focus model used by this ListView.

    • @p ModelObj is the FocusModel AJO to use.
    • @r this object
  • getFocusModel ()

    Returns the focus model used by this ListView.

    • @r An AJO holding the FocusModel.
  • focusModelProperty ()

    Returns the property holding the focus model.

    • @r An ObjectProperty AJO holding the FocusModel.
  • getOrientation ()

    Returns the orientation of this ListView as an enum value.

    • @r An AJO holding the javafx.geometry.Orientation enum value.
  • orientationProperty ()

    Returns the property holding the orientation.

    • @r An ObjectProperty AJO holding the Orientation.
  • getCellFactory ()

    Returns the cell factory callback used to create cells for items.

    • @r An AJO holding the Callback or null when none is set.
  • cellFactoryProperty ()

    Returns the property holding the cell factory callback.

    • @r An ObjectProperty AJO holding the Callback.
  • setFixedCellSize (double Size)

    Sets the fixed cell size in pixels. A value of 0 disables fixed sizing and falls back to the cell's preferred size.

    • @p Size is a double with the fixed cell size in pixels.
    • @r this object
  • getFixedCellSize ()

    Returns the fixed cell size.

    • @r A double with the fixed cell size in pixels.
  • fixedCellSizeProperty ()

    Returns the property holding the fixed cell size.

    • @r A DoubleProperty AJO.
  • setEditable (bool Editable)

    Sets whether the ListView allows editing of its items.

    • @p Editable is a bool; true enables editing.
    • @r this object
  • isEditable ()

    Returns whether the ListView is editable.

    • @r A bool with true when the ListView is editable.
  • editableProperty ()

    Returns the property holding the editable flag.

    • @r A BooleanProperty AJO.
  • getEditingIndex ()

    Returns the index of the item being edited, or -1 if no edit is active.

    • @r An int with the editing index, or -1.
  • editingIndexProperty ()

    Returns the read-only property holding the editing index.

    • @r A ReadOnlyIntegerProperty AJO.
  • setOnEditStart (callback Cb)

    Sets a callback that fires when an edit starts on a cell.

    • @p Cb is a callback that receives the ListView.EditEvent.
    • @r this object
  • getOnEditStart ()

    Returns the current onEditStart handler.

    • @r An AJO holding the EventHandler, or null.
  • onEditStartProperty ()

    Returns the property holding the onEditStart handler.

    • @r An ObjectProperty AJO holding the EventHandler.
  • setOnEditCommit (callback Cb)

    Sets a callback that fires when an edit is committed on a cell.

    • @p Cb is a callback that receives the ListView.EditEvent.
    • @r this object
  • getOnEditCommit ()

    Returns the current onEditCommit handler.

    • @r An AJO holding the EventHandler, or null.
  • onEditCommitProperty ()

    Returns the property holding the onEditCommit handler.

    • @r An ObjectProperty AJO holding the EventHandler.
  • setOnEditCancel (callback Cb)

    Sets a callback that fires when an edit is cancelled on a cell.

    • @p Cb is a callback that receives the ListView.EditEvent.
    • @r this object
  • getOnEditCancel ()

    Returns the current onEditCancel handler.

    • @r An AJO holding the EventHandler, or null.
  • onEditCancelProperty ()

    Returns the property holding the onEditCancel handler.

    • @r An ObjectProperty AJO holding the EventHandler.
  • edit (int Index)

    Starts an edit on the cell at the given index.

    • @p Index is an int with the row index to edit.
    • @r this object
  • scrollTo (int Index)

    Scrolls the ListView to make the given index visible.

    • @p Index is an int with the row index to scroll to.
    • @r this object
  • setOnScrollTo (callback Cb)

    Sets a handler that fires when the ListView is asked to scroll to an index.

    • @p Cb is a callback that receives the ScrollToEvent.
    • @r this object
  • getOnScrollTo ()

    Returns the current onScrollTo handler.

    • @r An AJO holding the EventHandler, or null.
  • onScrollToProperty ()

    Returns the property holding the onScrollTo handler.

    • @r An ObjectProperty AJO holding the EventHandler.
  • refresh ()

    Refreshes the visible cells of the ListView, re-running each visible cell's updateItem.

    • @r this object
  • getControlCssMetaData ()

    Returns the list of CssMetaData for this control.

    • @r A List AJO of CssMetaData entries.