List of usage examples for javafx.scene.control ProgressBar progressProperty
public final DoubleProperty progressProperty()
From source file:Main.java
@Override public void start(Stage primaryStage) { final Label label = new Label("Progress:"); final ProgressBar progressBar = new ProgressBar(0); final ProgressIndicator progressIndicator = new ProgressIndicator(0); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final TextArea textArea = new TextArea(); startButton.setOnAction((ActionEvent event) -> { startButton.setDisable(true);//from w w w. j a v a2 s .c o m progressBar.setProgress(0); progressIndicator.setProgress(0); textArea.setText(""); cancelButton.setDisable(false); copyWorker = createWorker(numFiles); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); progressIndicator.progressProperty().unbind(); progressIndicator.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener( (ObservableValue<? extends String> observable, String oldValue, String newValue) -> { textArea.appendText(newValue + "\n"); }); new Thread(copyWorker).start(); }); cancelButton.setOnAction((ActionEvent event) -> { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); progressIndicator.progressProperty().unbind(); progressIndicator.setProgress(0); textArea.appendText("File transfer was cancelled."); }); BorderPane root = new BorderPane(); Scene scene = new Scene(root, 500, 250, javafx.scene.paint.Color.WHITE); FlowPane topPane = new FlowPane(5, 5); topPane.setPadding(new Insets(5)); topPane.setAlignment(Pos.CENTER); topPane.getChildren().addAll(label, progressBar, progressIndicator); GridPane middlePane = new GridPane(); middlePane.setPadding(new Insets(5)); middlePane.setHgap(20); middlePane.setVgap(20); ColumnConstraints column1 = new ColumnConstraints(300, 400, Double.MAX_VALUE); middlePane.getColumnConstraints().addAll(column1); middlePane.setAlignment(Pos.CENTER); middlePane.add(textArea, 0, 0); FlowPane bottomPane = new FlowPane(5, 5); bottomPane.setPadding(new Insets(5)); bottomPane.setAlignment(Pos.CENTER); bottomPane.getChildren().addAll(startButton, cancelButton); root.setTop(topPane); root.setCenter(middlePane); root.setBottom(bottomPane); primaryStage.setScene(scene); primaryStage.show(); }
From source file:eu.over9000.skadi.ui.dialogs.PerformUpdateDialog.java
public PerformUpdateDialog(RemoteVersionResult newVersion) { this.chosen = new SimpleObjectProperty<>( Paths.get(SystemUtils.USER_HOME, newVersion.getVersion() + ".jar").toFile()); this.setHeaderText("Updating to " + newVersion.getVersion()); this.setTitle("Skadi Updater"); this.getDialogPane().getStyleClass().add("alert"); this.getDialogPane().getStyleClass().add("information"); final ButtonType restartButtonType = new ButtonType("Start New Version", ButtonBar.ButtonData.OK_DONE); this.getDialogPane().getButtonTypes().addAll(restartButtonType, ButtonType.CANCEL); Node btn = this.getDialogPane().lookupButton(restartButtonType); btn.setDisable(true);//from w w w . j a v a 2 s .c om Label lbPath = new Label("Save as"); TextField tfPath = new TextField(); tfPath.textProperty() .bind(Bindings.createStringBinding(() -> this.chosen.get().getAbsolutePath(), this.chosen)); tfPath.setPrefColumnCount(40); tfPath.setEditable(false); Button btChangePath = GlyphsDude.createIconButton(FontAwesomeIcons.FOLDER_OPEN, "Browse..."); btChangePath.setOnAction(event -> { FileChooser fc = new FileChooser(); fc.setTitle("Save downloaded jar.."); fc.setInitialFileName(this.chosen.getValue().getName()); fc.getExtensionFilters().add(new FileChooser.ExtensionFilter("Jar File", ".jar")); fc.setInitialDirectory(this.chosen.getValue().getParentFile()); File selected = fc.showSaveDialog(this.getOwner()); if (selected != null) { this.chosen.set(selected); } }); ProgressBar pbDownload = new ProgressBar(0); pbDownload.setDisable(true); pbDownload.setMaxWidth(Double.MAX_VALUE); Label lbDownload = new Label("Download"); Label lbDownloadValue = new Label(); Button btDownload = GlyphsDude.createIconButton(FontAwesomeIcons.DOWNLOAD, "Start"); btDownload.setMaxWidth(Double.MAX_VALUE); btDownload.setOnAction(event -> { btChangePath.setDisable(true); btDownload.setDisable(true); this.downloadService = new DownloadService(newVersion.getDownloadURL(), this.chosen.getValue()); lbDownloadValue.textProperty().bind(this.downloadService.messageProperty()); pbDownload.progressProperty().bind(this.downloadService.progressProperty()); this.downloadService.setOnSucceeded(dlEvent -> { btn.setDisable(false); }); this.downloadService.setOnFailed(dlFailed -> { LOGGER.error("new version download failed", dlFailed.getSource().getException()); lbDownloadValue.textProperty().unbind(); lbDownloadValue.setText("Download failed, check log file for details."); }); this.downloadService.start(); }); final GridPane grid = new GridPane(); grid.setHgap(10); grid.setVgap(10); grid.add(lbPath, 0, 0); grid.add(tfPath, 1, 0); grid.add(btChangePath, 2, 0); grid.add(new Separator(), 0, 1, 3, 1); grid.add(lbDownload, 0, 2); grid.add(pbDownload, 1, 2); grid.add(btDownload, 2, 2); grid.add(lbDownloadValue, 1, 3); this.getDialogPane().setContent(grid); this.setResultConverter(btnType -> { if (btnType == restartButtonType) { return this.chosen.getValue(); } if (btnType == ButtonType.CANCEL) { if (this.downloadService.isRunning()) { this.downloadService.cancel(); } } return null; }); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);// w w w . j av a2s .com final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);//from w w w . j a v a2s . c o m final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }
From source file:Main.java
@Override public void start(Stage primaryStage) { primaryStage.setTitle("Background Processes"); Group root = new Group(); Scene scene = new Scene(root, 330, 120, Color.WHITE); BorderPane mainPane = new BorderPane(); root.getChildren().add(mainPane);//from w w w . j av a 2 s . com final Label label = new Label("Files Transfer:"); final ProgressBar progressBar = new ProgressBar(0); final HBox hb = new HBox(); hb.setSpacing(5); hb.setAlignment(Pos.CENTER); hb.getChildren().addAll(label, progressBar); mainPane.setTop(hb); final Button startButton = new Button("Start"); final Button cancelButton = new Button("Cancel"); final HBox hb2 = new HBox(); hb2.setSpacing(5); hb2.setAlignment(Pos.CENTER); hb2.getChildren().addAll(startButton, cancelButton); mainPane.setBottom(hb2); startButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(true); progressBar.setProgress(0); cancelButton.setDisable(false); copyWorker = createWorker(); progressBar.progressProperty().unbind(); progressBar.progressProperty().bind(copyWorker.progressProperty()); copyWorker.messageProperty().addListener(new ChangeListener<String>() { public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) { System.out.println(newValue); } }); new Thread(copyWorker).start(); } }); cancelButton.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent event) { startButton.setDisable(false); cancelButton.setDisable(true); copyWorker.cancel(true); progressBar.progressProperty().unbind(); progressBar.setProgress(0); System.out.println("cancelled."); } }); primaryStage.setScene(scene); primaryStage.show(); }