有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在时间线内维护TableView选择?

我试图在后台时间线任务的TableView中维护我的选择

当我设置断点时,数据是正确的,并且我的行选择回调被触发。我之所以使用时间线,是因为我认为它可以处理GUI刷新,没有类似于Timers中的异常。这是我的代码:

private void initializeAutoRefresh() {
    this.autoRefreshTimeline = new Timeline(new KeyFrame(Duration.seconds(10), (ActionEvent event) -> {
        if (entries != null) {
            entries.clear();
            tableOfGames.getItems().clear();
            populateGameTable(); // Done through Web Service
            System.out.println("Refreshed data.");

            if (selectedGame!= null) {
                tableOfGames.requestFocus();
                tableOfGames.getSelectionModel().select(entries.indexOf(selectedGame));
            }
        }
    }));
    this.autoRefreshTimeline.setCycleCount(Timeline.INDEFINITE);
    autoRefreshTimeline.play();
}

刷新后,所选行不会被保留。理想的行为是选择蓝色的行,就像惯例一样。但是,GUI在刷新后不会保持不变,根据时间线,这是每10秒一次


共 (0) 个答案