如何使用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);
}
}输出结果
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短