简体   繁体   English

在 java 中通过多线程显示进度

[英]Display Progress by multi threading in java

I am trying to call a function initialStep() of MainApp class from ProcessStatements class.我正在尝试从ProcessStatements class 调用MainApp class 的 function initialStep() When the function initialStep() is called, i want to show progress bar to the user till the initialStep() function completes the execution.当调用 function initialStep()时,我想向用户显示进度条,直到initialStep() function 完成执行。

How can i do this using Java Swing?如何使用 Java Swing 做到这一点? Please someone help me out.请有人帮助我。 Thanks in advance:)提前致谢:)

I recommend using a SwingWorker for the task.我建议使用SwingWorker来完成这项任务。

The main issue is that the Swing stuff needs to be done on the EDT (Event Dispatch Thread).主要问题是 Swing 的东西需要在 EDT(事件调度线程)上完成。 The SwingWorker takes care of all that. SwingWorker 负责所有这些。 The progress bar can be a simple JProgressBar in a window or whatever is desired.进度条可以是 window 中的简单 JProgressBar 或任何需要的。

Happy coding.快乐编码。

J2SE Documentation report the same issue as example of using SwingWorker class: J2SE 文档报告了与使用 SwingWorker class 的示例相同的问题:
SwingWorker 摇摆工人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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