简体   繁体   中英

JavaFX runAsync with progress indicator and runLater

My code is loading connections asynchronously:

runAsync {
    controller.loadConnections(viewModel)
} ui {
    table.items = it
    table.refresh()
}

and inside loadConnections method:

//read connections from file and then 
Platform.runLater(() -> {
    CollectionsKt.bind(connections, databases, ConnectionsModel::new);
    connections.forEach(connection -> connection.setOwner(viewModel));
});

When I want to add progress bar as:

private val status = TaskStatus()
runAsync(status) {
    controller.loadConnections(viewModel)
} ui {
    table.items = it
    table.refresh()
}

But it blocks the progress indicator. As I understand 2 tasks ( progress and Platform.runLater ) are not executed in async . But how do I get this to work?

Try this code:

CompletableFuture.runAsync(() -> {
    for (int n = 1; n > size; n++)
        progressBar.setProgress(n);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM