个性化阅读
专注于IT技术分析

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);
	}

}

输出:

JavaFX进度指示器

使用setProgress()方法

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

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

输出:

JavaFX进度指示器
赞(0)
未经允许不得转载:srcmini » JavaFX进度指示器

相关推荐

评论 抢沙发

评论前必须登录!