Skip to content

Feature Request: Add programmatic scrolling and layout properties to GridView #1592

Description

@leewyatt

Hello ControlsFX team,

The GridView control is a powerful component for displaying virtualized collections. However, for building more advanced and user-friendly applications, it currently lacks a couple of key features that are common in other list/grid controls.

This issue proposes the addition of two related features:

  1. A public API for programmatic scrolling.
  2. Read-only properties to expose the grid's calculated layout (row and column count).

1. Programmatic Scrolling (scrollTo)

Motivation:
It is a very common requirement for an application to need to programmatically scroll the GridView to a specific item. Without this, it's impossible to implement many standard UX patterns.

Use Cases:

  • Search Results: After a user searches for an item, the application should automatically scroll the GridView to make that item visible.
  • State Restoration: When a user returns to a view, the application could scroll to their previously selected item, restoring their context.
  • Master-Detail Views: An external control (like a ListView or TreeView) could drive the GridView, and selecting an item in the master list should scroll to the corresponding cell in the GridView.

Proposed Solution:
Add new public methods to GridView:

public void scrollTo(int index);
public void scrollTo(T item);

2. Layout Information (rowCount and columnCount)

Motivation:
To correctly implement the scrollTo(int index) method, the rowIndex must be calculated from the item's absolute index. This calculation is only possible if the number of columns in the grid is known.

Furthermore, exposing these layout properties is valuable on its own for various application and testing purposes.

Use Cases:

  • UI Feedback: Displaying status information to the user, for example: "Showing 250 items in a 50x5 grid".
  • Dynamic UI Logic: Application logic might need to adapt based on how many items are currently laid out in the grid.
  • Automated Testing: It's crucial for UI tests to be able to verify that the GridView has been laid out with the expected number of rows and columns under specific conditions.

Proposed Solution:
Add new read-only properties to GridView:

public ReadOnlyIntegerProperty columnCountProperty();
public ReadOnlyIntegerProperty rowCountProperty();

These properties would be updated by the skin during layout passes.

By adding these APIs, GridView would become significantly more flexible and powerful for developers. I have a working implementation of this functionality prepared and would be happy to submit a Pull Request if this proposal is accepted.

Thank you for your consideration!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions