Flowless

repository·master·Indexed 42 days ago

https://github.com/fxmisc/flowless

A high-performance, low-level VirtualFlow implementation for JavaFX designed for efficiency during frequent item additions and deletions. It provides a layout component for vertical or horizontal flows that avoids the overhead of standard ListView cell updates, offering direct cell access, hit testing, and programmatic scrolling. Requires Java 9 or newer.

Tokens
765
Snippets
1
Records
4
Agent score
3%

What's inside Flowless

  1. Implement cells for Flowless

    master

    In Flowless, cells are simply Nodes. You are not required to inherit from ListCell. However, to ensure the virtual flow works correctly, your cells must implement specific layout methods based on the flow direction:

    For Vertical Virtual Flow:

    • computeMinWidth(-1)
    • computePrefWidth(-1)
    • computePrefHeight(width)

    For Horizontal Virtual Flow:

    • computeMinHeight(-1)
    • computePrefHeight(-1)
    • computePrefWidth(height)
  2. Understand the core concepts of Flowless

    master

    Flowless is an efficient VirtualFlow implementation for JavaFX that lays out cells in a vertical or horizontal flow. Unlike the standard JavaFX ListView, Flowless is a low-level layout component designed for high performance during item updates.

    Key Conceptual Differences from ListView

    • Dumb cells: Cells are treated as simple Nodes and do not encapsulate virtual flow logic. They do not necessarily store the index of the item they display. This gives VirtualFlow complete control over cell creation and updates.
    • Opt-in cell reuse: Cells are not reused by default. A new cell is created for each item. This simplifies implementation and avoids the overhead of updateItem if creating a new cell is comparable in cost.
    • No empty cells: If there are fewer items than the viewport capacity, Flowless does not use "empty cells" to fill the space. A cell is either displaying an item or is not displayed at all.

    When to use Flowless

    You will see the most benefit over ListView when you have frequent additions or deletions of items within the viewport and your updateItem method is computationally expensive.

  3. Include Flowless in your project

    master

    Flowless requires Java 9 or newer (as of version 0.6.5). You can include it in your project using Maven, Gradle, Sbt, or by manually adding the JAR to your classpath.

    Maven coordinates

    • Group ID: org.fxmisc.flowless
    • Artifact ID: flowless
    • Version: 0.7.4
    dependencies {
        implementation group: 'org.fxmisc.flowless', name: 'flowless', version: '0.7.4'
    }
  4. Use the VirtualFlow public API

    master

    The VirtualFlow class provides several advanced methods for interacting with the layout that are not available in standard JavaFX ListView implementations:

    • Direct cell access: Use getCell(itemIndex) or getCellIfVisible(itemIndex) for measurement or direct manipulation.
    • Visible cells: Retrieve a list of all currently visible cells via visibleCells().
    • Hit testing: Use hit(double x, double y) to convert viewport coordinates into a cell index and relative coordinates within that cell.
    • Navigation: Use show(itemIndex, region) for fine-grained navigation to a specific subregion of a cell, or show(itemIndex) for standard navigation.
    • Scrolling: Use scrollXBy(deltaX) and scrollYBy(deltaY) for programmatic scrolling.
    • Gravity: You can configure VirtualFlow so that cells stick to the bottom (vertical flow) or the right (horizontal flow) when the number of items is less than the viewport capacity.