除非调整大小,否则JavaFX ListView不正确的滚动条行为

时间:2018-06-07 06:58:08

标签: listview javafx

我创建了一个使用Application的{​​{1}}。对于此ListView,我使用ListView s实现了我自己的CellFactory

这些Expandable Node包括一些简单的Node和一个LayoutPane

用户可以点击TextFlow / Button来显示更多内容。

Hyperlink调整大小时,Cell会添加ListView

但是Vertical Scrollbar的句柄太小了 - 滚动停在高度的三分之一处ScrollbarWarning 崩溃)

  

[DateTime] com.sun.javafx.scene.control.skin.VirtualFlow addTrailingCells

     

信息:索引超过maxCellCount。检查类[package] .AppListView

的大小计算

如果您抓住Application并调整其大小,则Stage会调整为正确的尺寸)

  

我在SO上搜索了类似的问题并找到了一些,但没有一个人有一个示例应用程序而且没有一个人有解决方案 - 所以不要标记为重复

以下是我的示例应用程序的代码

Scrollbar

和可扩展节点:

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.control.ListCell;
import javafx.scene.control.ListView;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class AppListView extends Application {
    public static final String BIG = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod\n"
            + " tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, \n"
            + "quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo\n"
            + " consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie\n"
            + " consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto\n"
            + " odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait\n"
            + " nulla facilisi. Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet\n"
            + " doming id quod mazim placerat facer possim assum. Typi non habent claritatem insitam;\n"
            + " est usus legentis in iis qui facit eorum claritatem. Investigationes demonstraverunt \n"
            + "lectores legere me lius quod ii legunt saepius. Claritas est etiam processus dynamicus,\n"
            + " qui sequitur mutationem consuetudium lectorum. Mirum est notare quam littera gothica,\n"
            + " quam nunc putamus parum claram, anteposuerit litterarum formas humanitatis per seacula \n"
            + "quarta decima et quinta decima. Eodem modo typi, qui nunc nobis videntur parum clari, \n"
            + "fiant sollemnes in futurum.";

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        ObservableList<String> data = FXCollections.observableArrayList();

        data.addAll(BIG, BIG, BIG);

        ListView<String> listView = new ListView<String>();
        listView.setCellFactory((ListView<String> l) -> new ListCell<String>() {
            ExpandableNode ui;

            @Override
            public void updateItem(String item, boolean empty) {
                super.updateItem(item, empty);
                setText(null);
                if (item != null) {
                    setGraphic(createUi(item));
                }
                if (empty) {
                    setGraphic(null);
                }
            }

            public ExpandableNode createUi(String item) {
                if (ui == null) {
                    ui = new ExpandableNode();
                }
                ui.setContent(item);
                return ui;
            }
        });

        listView.setItems(data);

        StackPane root = new StackPane();
        root.getChildren().add(listView);
        Scene scene = new Scene(root, 550, 300);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
}

0 个答案:

没有答案