要在JavaFX中正确使用ProgressIndicator,您需要遵循以下步骤: 1. 创建ProgressIndicator对象: ``` ProgressIndicator progressIndicator = new ProgressIndicator(); ``` 2. 设置ProgressIndicator的大小和位置: ``` progressIndicator.setLayoutX(100); progressIndicator.setLayoutY(100); progressIndicator.setPrefSize(50, 50); ``` 3. 将ProgressIndicator添加到场景中: ``` Group root = new Group(); root.getChildren().add(progressIndicator); Scene scene = new Scene(root, 300, 250); primaryStage.setScene(scene); primaryStage.show(); ``` 4. 在需要显示进度的代码块中,启动ProgressIndicator: ``` progressIndicator.setProgress(-1.0f); ``` 5. 在代码块完成后,停止ProgressIndicator: ``` progressIndicator.setProgress(1.0f); ``` 6. 如果需要在进度条上显示具体的进度,可以使用setProgress()方法: ``` progressIndicator.setProgress(0.5f); ``` 这些步骤将帮助您正确使用ProgressIndicator在JavaFX中显示进度。