Example of Progress Bar and Progress Indicator in JavaFX 8
Here is the code
/////////////////////////////////////////////////////////////////////////////////////////
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
/**
*
* @author Ravi Sharma
*
*/
public class ProgressSample extends Application {
final Float[] values = new Float[] { -1.0f, 0f, 0.6f, 1.0f };
final Label[] labels = new Label[values.length];
final ProgressBar[] pbs = new ProgressBar[values.length];
final ProgressIndicator[] pins = new ProgressIndicator[values.length];
final HBox hbs[] = new HBox[values.length];
@Override
public void start(Stage stage) {
Group root = new Group();
Scene scene = new Scene(root, 400, 300);
stage.setScene(scene);
stage.setTitle("Progress Controls");
final VBox vb = new VBox();
for (int i = 0; i < values.length; i++) {
// create label
final Label label = labels[i] = new Label();
label.setText("progress at :" + values[i]);
// create progress bar
final ProgressBar pb = pbs[i] = new ProgressBar();
pb.setProgress(values[i]);
// create progress indicator
final ProgressIndicator pin = pins[i] = new ProgressIndicator();
pin.setProgress(values[i]);
final HBox hb = hbs[i] = new HBox();
hb.setSpacing(5);
hb.setAlignment(Pos.CENTER);
// Add label , progress bar and progress indicator
hb.getChildren().addAll(label, pb, pin);
HBox.setHgrow(hb, Priority.ALWAYS);
}
vb.setSpacing(5);
vb.setAlignment(Pos.CENTER);
// add list of hbox in vbox
vb.getChildren().addAll(hbs);
VBox.setVgrow(vb, Priority.ALWAYS);
// set vbox as root of scene
scene.setRoot(vb);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Comments
Post a Comment