如何使用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);
}
}输出结果
热门推荐
3 入学校简短祝福语
10 给女儿祝福语简短精辟
11 酒店客人祝福语简短
12 2026猪年祝福语简短语
13 给儿子祝福语简短霸气
14 客户投标祝福语简短范文
15 新人结婚简短祝福语大全
16 祝福语简短七夕
17 道教生日祝福语简短大全
18 老师新婚快乐祝福语简短