javafx - 带有进度指示器和 runLater 的 JavaFX runAsync
问题描述
我的代码正在异步加载连接:
runAsync {
controller.loadConnections(viewModel)
} ui {
table.items = it
table.refresh()
}
和内部loadConnections
方法:
//read connections from file and then
Platform.runLater(() -> {
CollectionsKt.bind(connections, databases, ConnectionsModel::new);
connections.forEach(connection -> connection.setOwner(viewModel));
});
当我想将进度条添加为:
private val status = TaskStatus()
runAsync(status) {
controller.loadConnections(viewModel)
} ui {
table.items = it
table.refresh()
}
但它会阻止进度指示器。据我了解 2 个任务 (progress
和Platform.runLater
) 没有在async
. 但是我怎样才能让它工作呢?
解决方案
试试这个代码:
CompletableFuture.runAsync(() -> {
for (int n = 1; n > size; n++)
progressBar.setProgress(n);
});
推荐阅读
- ios - 将 UIKit 内容插入 SwiftUI 视图层次结构
- c# - 如何在没有 shell 命令的情况下使用 EF Core 数据种子
- javascript - 如何在函数之外获取回调数据(AWS SDK)(非异步)
- c - 如何更改 cmocka 打印格式?
- etl - 如何在输入中创建组并在 Talend 中的每个组中选择特定行?
- node.js - React 应用程序处理具有依赖关系的模型
- html - 使用类的唯一子选择器
- java - Gradle 构建失败:重复条目 *.class
- sql - 什么是内联函数?
- macos - CMake:IMPORTED_SONAME 对 macOS 上的导入库没有影响