如何使进度条的进度摆动? [英] how to make the progression of a progressbar swing?
问题描述
我想创建一个在设备中安装文件的复制。但我有一个问题实现进度,我在我的fram中使用的代码调用类安装是在下面给出,execShellCmd是调用的方法安装到所有设备。 value是Install类生成的静态值。我想实现一个进度条安装和价值,以便给安装的进度。
I would like to creat an apllication that install files in devices. but i have a problem to implement the progress, the code that i use in my fram to call the class to install is given below, execShellCmd is the method called to install to all devices. value is a static value gived by the Install class. i would like to implement a progressbar relited to install and value in order to give the progression of installation.
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
Thread t;
t = new Thread(){
private int postion;
public void run(){
Install install = new Install();
int position = 0;
String fileName = directory;
String shellCommand = fileName;
// for (int position =0; postion < 105;position +5) {
jProgressBar1.setValue(Install.value);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
position += 5;
//}
install.execShellCmd(shellCommand);
//jTextArea1.setText(error.err.toString());
}
};
t.start();
}
推荐答案
如下所示在这里,您可以使用 ProcessBuilder
来执行您的脚本。解析从 getInputStream()
获得的组合流,以评估脚本的实际进度。使用该信息调整您的 JProgresBar
。要在GUI中保持活性,请在 doInBackground() /concurrency/worker.htmlrel =nofollow> SwingWorker
,您可以从中调用 setProgress()
。
As shown here, you can use ProcessBuilder
to execute your script. Parse the combined streams, obtained from getInputStream()
, to assess the script's actual progress. Use that information to condition your JProgresBar
. To preserve liveness in the GUI, do this in the doInBackground()
method of a SwingWorker
, from which you can invoke setProgress()
.
这篇关于如何使进度条的进度摆动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!