如何更新jprogress bar [英] How to update jprogress bar

查看:47
本文介绍了如何更新jprogress bar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个简单的 JForm 和一个 JDialog.JDialog 框包含一个 JProgressBar 元素,我在 JDialog 中放置了一个方法,

I have a simple JForm and a JDialog in my application. JDialog box contains a JProgressBar eliment and I'put a method in the JDialog as,

 public void updateProgress(int val){
        prgProgress.setValue(val); //prgProgress-> name of the JProgressBar
    }

更新进度条.

当我尝试从 JForm 更新 JDialog 中的进度条时,JProgressBar 没有按预期更新,请告诉我可能是什么错误,

When I try to update the progress bar in my JDialog from the JForm, JProgressBar doesn't update as expected please tell me what could be the error,

例如

public class Status extends javax.swing.JDialog{
 private javax.swing.JProgressBar prgProgress = new javax.swing.JProgressBar;
.....

public void updateProgress(int val){
            prgProgress.setValue(val); //prgProgress-> name of the JProgressBar
        }

.....

}

public class MyForm extends javax.swing.JInternalFrame {
    Status s = new Status();
    s.setVisible(true);
    for(int i=0; i<100; i++){
        s.updateProgress(i);
    }

}

推荐答案

Swing 中的并发,Swing 是单线程的,如果您从 EDT 更新 GUI,则不会发生任何事情,您必须实现 SwingWorker 用于更新 JProgressBar,带有描述的示例这里

You have a issue with Concurency in Swing, Swing is single threaded and nothing happends if you update GUI out of EDT, you have to implement SwingWorker for updating JProgressBar, example with descriptions here

这篇关于如何更新jprogress bar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆