Saturday, June 4, 2016

28. Progress Controls

A progress bar and progress indicator are used.


They are controlled by value of val, which is 0.7 in this example.


package ex28;

import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;

public class Ex28  extends Application {

    @Override
    public void start(Stage stage) {
        GridPane root = new GridPane();
        root.setVgap(10);
        root.setHgap(10);
        root.setAlignment(Pos.CENTER);
        
        double val = 0.7;
        
        Label lab1 = new Label();
        lab1.setText("progress: " + val);
        GridPane.setConstraints(lab1, 0, 0);
        
        Label lab2 = new Label();
        lab2.setText("Progress Bar");
        GridPane.setConstraints(lab2, 0, 1);
 
        ProgressBar prBar = new ProgressBar();
        prBar.setProgress(val);
        GridPane.setConstraints(prBar, 1, 1);
        
        Label lab3 = new Label();
        lab3.setText("Progress Indicator");
        GridPane.setConstraints(lab3, 0, 2);
 
        ProgressIndicator prInd = new ProgressIndicator();
        prInd.setProgress(val);
        GridPane.setConstraints(prInd, 1, 2);
        
        root.getChildren().addAll(lab1, lab2, prBar, lab3, prInd);
        Scene scene = new Scene(root, 400, 200);
        stage.setScene(scene);
        stage.setTitle("Example 28. Progress Controls");
        stage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

This is the output:


No comments:

Post a Comment