Skip to content

Instantly share code, notes, and snippets.

@rikmeijer
Created May 15, 2019 09:18
Show Gist options
  • Select an option

  • Save rikmeijer/147e65d8a4ba330d3578a06ecf09c6e8 to your computer and use it in GitHub Desktop.

Select an option

Save rikmeijer/147e65d8a4ba330d3578a06ecf09c6e8 to your computer and use it in GitHub Desktop.
PROG4_Wk4b
package PROG4_WK4b;
import javafx.application.Application;
import javafx.concurrent.Task;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
Task<Void> task = new Task<Void>() {
@Override public Void call() throws InterruptedException {
for (int i=0; i<=100; i+=10) {
updateProgress(i, 100);
Thread.sleep(1000);
}
return null;
}
};
ProgressBar bar = new ProgressBar();
bar.progressProperty().bind(task.progressProperty());
bar.setMinWidth(800);
bar.setMinHeight(200);
new Thread(task).start();
BorderPane pane = new BorderPane();
pane.setMinWidth(400);
pane.setMinHeight(300);
pane.setCenter(bar);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
@rikmeijer
Copy link
Author

@rikmeijer
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment