在Java中,可以使用JavaFX库中的ProgressIndicator类来显示进度指示器。以下是一个简单的示例代码:
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.ProgressIndicator; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class ProgressIndicatorExample extends Application { @Override public void start(Stage primaryStage) { ProgressIndicator progressIndicator = new ProgressIndicator(); progressIndicator.setProgress(0.5); // 设置进度,0表示0%,1表示100% StackPane root = new StackPane(); root.getChildren().add(progressIndicator); Scene scene = new Scene(root, 200, 200); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } }
在这个示例中,创建了一个ProgressIndicator对象,并设置其进度为0.5(50%)。将ProgressIndicator添加到StackPane中,并将StackPane作为根节点添加到场景中。最后显示场景。
这是一个基本的使用进度指示器的示例,你可以根据自己的需求进一步定制。