javafx,如何在打印到文本区域时显示进度条
javafx , how to show progress bar while printing into text area
我是编程新手,努力学习。
我的 "app" 运行 bat 测试文件,所有结果都打印在 textarea 中,运行良好。
但我现在的目标是呈现进度条,在打印到文本区域时显示进度。
我该怎么做 ?我已经阅读了一些指南并尝试了一些方法,但它对我不起作用
这是 运行 蝙蝠文件
按钮背后的方法
public void RunTestScrip() throws IOException {
Process p = Runtime.getRuntime().exec(path);
final InputStream stream = p.getInputStream();
new Thread(new Runnable() {
public void run() {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(stream));
String line = null;
while ((line = reader.readLine()) != null) {
console.appendText("\n" + line);
progressBar.progressProperty().bind(RunTestScrip()); // dont know how to use it right in my code
}
} catch (Exception e) {
// TODO
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// ignore
}
}
}
}
}).start();
我认为该脚本无法更新 javafx ProgressBar。最简单的方法是创建您自己的进度规则(可能基于您当前附加到控制台的输出)。
这里有一篇关于如何在 javafx 中创建工作进度条的精彩 tutorial。希望您能找到相应更新进度的方法。
编辑:
我添加了一个可以在教程中找到的小示例,以防提供的 link 中断。
// initialization of a progressBar with 'indeterminate progress'
ProgressBar pb = new ProgressBar(-1.0D);
// to set the current state of a progress bar you simply do the following
pb.setProgress(current_progress);
请注意,进度是介于 0.0D 和 1.0D 之间的值(例如百分比)。
-1.0D 的值表示进度不确定。
我是编程新手,努力学习。 我的 "app" 运行 bat 测试文件,所有结果都打印在 textarea 中,运行良好。 但我现在的目标是呈现进度条,在打印到文本区域时显示进度。 我该怎么做 ?我已经阅读了一些指南并尝试了一些方法,但它对我不起作用
这是 运行 蝙蝠文件
按钮背后的方法public void RunTestScrip() throws IOException {
Process p = Runtime.getRuntime().exec(path);
final InputStream stream = p.getInputStream();
new Thread(new Runnable() {
public void run() {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(stream));
String line = null;
while ((line = reader.readLine()) != null) {
console.appendText("\n" + line);
progressBar.progressProperty().bind(RunTestScrip()); // dont know how to use it right in my code
}
} catch (Exception e) {
// TODO
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
// ignore
}
}
}
}
}).start();
我认为该脚本无法更新 javafx ProgressBar。最简单的方法是创建您自己的进度规则(可能基于您当前附加到控制台的输出)。
这里有一篇关于如何在 javafx 中创建工作进度条的精彩 tutorial。希望您能找到相应更新进度的方法。
编辑:
我添加了一个可以在教程中找到的小示例,以防提供的 link 中断。
// initialization of a progressBar with 'indeterminate progress'
ProgressBar pb = new ProgressBar(-1.0D);
// to set the current state of a progress bar you simply do the following
pb.setProgress(current_progress);
请注意,进度是介于 0.0D 和 1.0D 之间的值(例如百分比)。 -1.0D 的值表示进度不确定。