Skip to main content

Overview

JList is a wrapper around JavaFX ListView that provides:
  • Built-in pagination controls
  • Infinite scroll capability
  • Custom cell factory support with automatic styling
  • Easy item management

Constructor

JList<T>()
constructor
Creates a new generic list for type T.

Basic Usage

JList&lt;User&gt; list = new JList&lt;&gt;();
list.setCellFactory(param -> new ListCell<User>() {
    @Override
    protected void updateItem(User user, boolean empty) {
        super.updateItem(user, empty);
        if (empty || user == null) {
            setText(null);
            setGraphic(null);
        } else {
            setText(user.getName());
        }
    }
});
list.setItems(userData);

Cell Factory

setCellFactory(value)
void
Sets the cell factory for rendering list items. Automatically adds the “j-list-card-cell” style class to each cell.
list.setCellFactory(param -> new ListCell<Product>() {
    @Override
    protected void updateItem(Product product, boolean empty) {
        super.updateItem(product, empty);
        if (empty || product == null) {
            setGraphic(null);
        } else {
            JCard card = new JCard();
            card.setTitle(product.getName());
            card.setDescription(product.getDescription());
            setGraphic(card);
        }
    }
});

Data Management

setItems(items)
void
Sets the list’s data source.
addItem(item)
void
Adds a single item to the list.

Pagination

setPaginationVisible(boolean)
void
Shows or hides the pagination controls.
getPagination()
JPagination
Returns the underlying JPagination component for advanced control.

Infinite Scroll

setOnScrollBottom(action)
void
Enables infinite scroll and sets a callback that fires when the user scrolls to 90% of the list.
list.setOnScrollBottom(() -> {
    // Load more items
    loadMoreItems();
});

Access to Underlying Components

getListView()
ListView<T>
Returns the underlying JavaFX ListView for advanced customization.

Example: Card List

JList&lt;Article&gt; articleList = new JList&lt;&gt;();

articleList.setCellFactory(param -> new ListCell<Article>() {
    @Override
    protected void updateItem(Article article, boolean empty) {
        super.updateItem(article, empty);
        if (empty || article == null) {
            setGraphic(null);
        } else {
            VBox card = new VBox(8);
            card.getStyleClass().add("article-card");
            
            JLabel title = new JLabel(article.getTitle());
            title.withStyle("text-lg", "font-bold");
            
            JParagraph excerpt = new JParagraph(article.getExcerpt());
            excerpt.withStyle("text-muted");
            
            JButton readMore = new JButton("Read More");
            readMore.setVariant("link");
            
            card.getChildren().addAll(title, excerpt, readMore);
            setGraphic(card);
        }
    }
});

articleList.setItems(articles);
articleList.setOnScrollBottom(() -> loadMoreArticles());

Build docs developers (and LLMs) love