简体   繁体   English

Java在循环中使用jProgressBar

[英]Java using jProgressBar within loop

i build an Application and i have a button do a lot of things when i press it the application is freeze it for some second. 我建立一个应用程序,当我按下它时,我有一个按钮做很多事情,应用程序冻结了一段时间。 So i just want put a jProgressBar here is my code : 所以我只想在这里放一个jProgressBar是我的代码:

String s="";
long l=System.currentTimeMillis();

for(int k=0;k<jTable3.getRowCount();k++)
{
    s=jTable3.getValueAt(k, 0).toString();
    myFunction(s);
}

long l2=System.currentTimeMillis();
JOptionPane.showMessageDialog(rootPane, "We are done in just "+(l2-l)+" MS");

Any help or suggest? 任何帮助或建议?

What you need to do is perform your lengthy/taxing operations on another thread, and then, from that thread, adjust the value of your JProgressBar . 你需要做的是在另一个线程上执行冗长/征税操作,然后从该线程调整JProgressBar的值。 The progress will then be visible. 然后可以看到进展。

Some information on concurrency and threads. 有关并发和线程的一些信息。

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

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