gpt4 book ai didi

java - Swing - 等待渲染完成

转载 作者:行者123 更新时间:2023-11-30 01:47:35 26 4
gpt4 key购买 nike

我有一个小问题。我正在尝试在 JTextPane 中显示非常大的文本(~ 10 MB)。我想显示一个工作对话框(使用动画 gif 作为无限期进度条),直到 JTextPane 渲染文本。

到目前为止,我已经有了这个(kotlin):

val worker = WorkerWindow(this, "Drawing text...") // JDialog
SwingUtilities.invokeLater {
worker.isVisible = true
}
SwingUtilities.invokeLater {
textPane.document = logcat.document // Long UI operation
worker.dispose()
}

遗憾的是,在文档渲染完成之前,该对话框立即关闭。当 EDT 完成操作或其他操作时,我可以使用任何类型的回调吗?

Worker dialog

最佳答案

您可以在这里查看 Swing 工作人员:https://docs.oracle.com/javase/8/docs/api/index.html?javax/swing/SwingWorker.html这将使您能够更好地控制 swing 中的异步任务。

另一个问题:为什么不设置工作窗口可见性并在一个线程中加载文档?像这样:

val worker = WorkerWindow(this, "Drawing text...") // JDialog

SwingUtilities.invokeLater {
worker.isVisible = true
textPane.document = logcat.document // Long UI operation
worker.dispose()
}

看起来更容易...

关于java - Swing - 等待渲染完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57382012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com