您必须更新Swing事件调度线程上的JProgress栏。您不能在任何其他线程上修改Swing组件。
您唯一的其他选择是在启动线程之前,将JProgress栏设置为“不确定”,以使进度栏来回移动。
例如
progBar.setIndeterminate(true);
请参阅SwingWorker
Javadoc:http
:
//docs.oracle.com/javase/6/docs/api/javax/swing/SwingWorker.html
如果您不想使用SwingWorker,则另一个
SwingUtilities.invokeLater方法是
//inside your long running thread when you want to update a Swing componentSwingUtilities.invokeLater(new Runnable() { public void run() { //This will be called on the EDT progressBar.setValue(progressBar.getValue() + 1); }});


