📜  javafx 进度指示器

📅  最后修改于: 2020-10-14 06:16:34             🧑  作者: Mango

JavaFX进度指示器

进度指示器在某种程度上类似于进度栏。它没有向用户显示模拟进度,而是显示了数字进度,因此用户可以按百分比知道完成的工作量。

它由javafx.scene.control.ProgressIndicator类表示。需要实例化此类以创建进度指示器。以下代码将进度指示器实现到我们的应用程序中。

package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class Progress_Indicator extends Application{

@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
ProgressIndicator PI=new ProgressIndicator();

StackPane root = new StackPane();
root.getChildren().add(PI);
Scene scene = new Scene(root,300,200);
primaryStage.setScene(scene);
primaryStage.setTitle("Progress Indicator Example");
primaryStage.show();

}
public static void main(String[] args) {
launch(args);
}

}

输出:

使用setProgress()方法

将以下行添加到上面显示的代码中,以设置75%的进度值。

ProgressIndicator PI=new ProgressIndicator();
PI.setProgress(0.75f);

输出: