本文介绍了javafx:显示流程进度的进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在功能运行时显示进度条。展示它的最佳方式是什么?基本上我正在构建一个程序,只需单击即可发送多封邮件。在发送邮件时,我想在发送邮件时显示进度条。
I want to show progress bar while a functionality is running. What is the best way to show it? Basically I am building a program to send multiple mails on a single click. While sending the mail I want to show progress bar while sending the mails.
推荐答案
在这种情况下,最佳解决方案是使用任务
。
The best solution in this case is using a Task
.
示例:
Task<Parent> yourTaskName = new Task<Parent>() {
@Override
public Parent call() {
// DO YOUR WORK
//method to set progress
updateProgress(workDone, max);
//method to set labeltext
updateMessage(message);
}
};
//ProgressBar
ProgressBar pBar = new ProgressBar();
//Load Value from Task
pBar.progressProperty().bind(yourTaskName.progressProperty());
//New Loading Label
Label statusLabel = new Label();
//Get Text
statusLabel.setText("Loading...");
//Layout
VBox root = new VBox(statusLabel, pBar);
//SetFill Width TRUE
root.setFillWidth(true);
//Center Items
root.setAlignment(Pos.CENTER);
//SetOnSucceeded methode
yourTaskName.setOnSucceeded(new EventHandler<WorkerStateEvent>() {
@Override
public void handle(WorkerStateEvent event) {
System.out.println("Finish");
}
});
//Start Thread
Thread loadingThread = new Thread(yourTaskName);
loadingThread.start();
希望这可以帮到你。
PS :任务中的代码作为 ...
P.S.: The code in the task run as a Thread...
这篇关于javafx:显示流程进度的进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!