如何使用 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) {
//Creating a progress bar
ProgressBar progress = new ProgressBar();
//Setting value to the progress bar
progress.setProgress(0.5);
//Creating a progress indicator
ProgressIndicator indicator = new ProgressIndicator(0.6);
//Setting the size of the progress bar
progress.setPrefSize(300, 30);
//Creating a hbox to hold the progress bar and progress indicator
HBox hbox = new HBox(20);
hbox.setSpacing(5);
hbox.setPadding(new Insets(75, 150, 50, 60));
hbox.getChildren().addAll(progress, indicator);
//Setting the stage
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);
}
}輸出

廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP