[英]jProgressBar with Database
how do I display the progress in a jProgressBar when I write something in the database? 在数据库中编写内容时,如何在jProgressBar中显示进度?
Thanks 谢谢
You would typically use a SwingWorker
to update the JProgressBar
from the Event Dispatch thread whilst performing the database write operations on the background thread. 通常,您将使用
SwingWorker
从事件分发线程更新JProgressBar
,同时在后台线程上执行数据库写入操作。 For example: 例如:
// Create progress bar to represent 10 items we wish to write to
// the database (hence min := 0, max := 10);
JProgressBar pBar = new JProgressBar(0, 10);
// TODO: Add progress bar to panel and display.
// Invoke SwingWorker to perform database write operations on
// background thread.
new SwingWorker<Void, Integer>() {
/**
* Called on background worker thread. Performs DB write operations.
*/
public Void doInBackground() {
for (int i=0; i<10; ++i) {
// TODO: Perform DB write operation here.
// Publish progress so far back to Event Dispatch Thread.
publish(i);
}
}
/**
* Called on EDT with intermediate progress result(s).
*/
protected void process(List<Integer> chunks) {
if (!chunks.isEmpty()) {
int progress = chunks.get(chunks.size() - 1);
pBar.setValue(progress);
}
}
/**
* Called on EDT when DB write task has completely finished.
*/
protected void done() {
pBar.setValue(pBar.getMaximum());
// TODO: Hide progress bar, etc.
}
}.execute()
在您的服务器上,您必须收集进度数据并以jProgressBar可以查询它的方式提供它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.