进度指示器(ProgressIndicator
)以动态更改饼图的形式显示JavaFX中的操作进度。以下代码显示如何使用不确定值创建ProgressIndicator
。
import javafx.application.Application
import javafx.scene.Group
import javafx.scene.Scene
import javafx.scene.control.ProgressIndicator
import javafx.stage.Stage
public class Main extends Application {
@Override
public void start(Stage stage) {
Group root = new Group()
Scene scene = new Scene(root, 260, 80)
stage.setScene(scene)
Group g = new Group()
ProgressIndicator p1 = new ProgressIndicator()
g.getChildren().add(p1)
scene.setRoot(g)
stage.show()
}
public static void main(String[] args) {
launch(args)
}
}
上面的代码生成以下结果。
创建ProgressIndicator
以下代码通过传递progress
值来创建ProgressIndicator
。
ProgressIndicator pi = new ProgressIndicator(0.6)
可以使用空构造函数创建没有参数的进度指示器。然后可以使用setProgress()
方法分配值。
如果无法确定进度,可以在不确定模式下设置进度控制,直到确定任务的长度。
以下代码显示如何创建一个完成25%的ProgressIndicator
。
import javafx.application.Application
import javafx.scene.Group
import javafx.scene.Scene
import javafx.scene.control.ProgressIndicator
import javafx.stage.Stage
public class Main extends Application {
@Override
public void start(Stage stage) {
Group root = new Group()
Scene scene = new Scene(root, 260, 80)
stage.setScene(scene)
Group g = new Group()
ProgressIndicator p1 = new ProgressIndicator()
p1.setProgress(0.25F)
g.getChildren().add(p1)
scene.setRoot(g)
stage.show()
}
public static void main(String[] args) {
launch(args)
}
}
上面的代码生成以下结果。