如何使用JavaFX创建进度栏?

进度条是事件进展的指示器(一系列步骤)。您可以通过实例化javafx.scene.control.ProgressBar类来创建进度条

示例

以下示例演示了ProgressBar的创建。

import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class ProgressBarExample extends Application {
   public void start(Stage stage) {
      //创建进度条
      ProgressBar progress = new ProgressBar();
      //在进度条上设置值
      progress.setProgress(0.5);
      //创建进度指示器
      ProgressIndicator indicator = new ProgressIndicator(0.6);
      //设置进度条的大小
      progress.setPrefSize(300, 30);
      //创建一个hbox来保存进度条和进度指示器
      HBox hbox = new HBox(20);
      hbox.setSpacing(5);
      hbox.setPadding(new Insets(75, 150, 50, 60));
      hbox.getChildren().addAll(progress, indicator);
      //设置舞台
      Group root = new Group(hbox);
      Scene scene = new Scene(root, 595, 200, Color.BEIGE);
      stage.setTitle("Progress Bar Example");
      stage.setScene(scene);
      stage.show();
   }
   public static void main(String args[]){
      launch(args);
   }
}

输出结果