Example usage for javafx.scene.control Button setOnAction

List of usage examples for javafx.scene.control Button setOnAction

Introduction

In this page you can find the example usage for javafx.scene.control Button setOnAction.

Prototype

public final void setOnAction(EventHandler<ActionEvent> value) 

Source Link

Usage

From source file:de.rkl.tools.tzconv.TimezoneConverter.java

private Node createTemplateFileSelection() {
    final Button templateFileChooserButton = new Button();
    templateFileChooserButton.setText("Select template...");
    templateFileChooserButton.setOnAction(
            event -> applicationModel.templateFile.setValue(createTemplateFileChooser().showOpenDialog(null)));
    return templateFileChooserButton;
}

From source file:org.jacp.demo.perspectives.ContactPerspective.java

@PostConstruct
/**/*from ww  w.  jav  a  2 s .c  o m*/
 * create buttons in tool bars; menu entries
 */
public void PostConstructPerspective(final FXComponentLayout layout, final ResourceBundle resourceBundle) {
    LOGGER.debug("PostConstructPerspective ressource:" + resourceBundle);
    // create button in toolbar; button should switch top and bottom id's
    final JACPToolBar north = layout.getRegisteredToolBar(NORTH);
    final JACPToolBar south = layout.getRegisteredToolBar(SOUTH);
    final JACPToolBar west = layout.getRegisteredToolBar(WEST);
    final JACPToolBar east = layout.getRegisteredToolBar(EAST);

    final Button custom = new Button("switch");
    custom.setTooltip(new Tooltip("Switch Components"));
    custom.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(final ActionEvent e) {
            context.send(SWITCH_MESSAGE);

        }
    });
    north.addOnEnd(context.getId(), custom);

    // TEST OPTIONBUTTON ON NORTH
    north.addOnEnd(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("another Button", layout, BOTTOM, 10));
    north.addToCenter(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("another Button", layout, BOTTOM, 10));
    north.add(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("another Button", layout, BOTTOM, 10));
    west.add(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("another Button", layout, RIGHT));
    west.addToCenter(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("another Button", layout, RIGHT));
    west.addOnEnd(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("another Button", layout, RIGHT));
    east.addOnEnd(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("right Button", layout, LEFT));
    east.add(context.getId(), JACPOptionButtonCreator.createDefaultOptionButton("right Button", layout, LEFT));
    east.addToCenter(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("right Button", layout, LEFT));
    south.add(context.getId(), JACPOptionButtonCreator.createDefaultOptionButton("bottom Button", layout, TOP));
    south.addToCenter(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("bottom Button", layout, TOP));
    south.addOnEnd(context.getId(),
            JACPOptionButtonCreator.createDefaultOptionButton("bottom Button", layout, TOP));

    JACPHoverMenu menu = new JACPHoverMenu("Hovermenu", layout);

    VBox p = new VBox();
    p.setPadding(new Insets(10));
    Button b = new Button("HELLO");
    CheckBox check = new CheckBox("checkbox");

    p.getChildren().addAll(b, check);

    ColorPicker picker = new ColorPicker();
    menu.getContentPane().getChildren().add(p);

    north.addToCenter(context.getId(), menu);
    north.addToCenter(context.getId(), picker);

}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("JavaFX Welcome");
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//from www.j  av a 2  s  .  c o m
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    Text scenetitle = new Text("Welcome");
    scenetitle.setFont(Font.font("Tahoma", FontWeight.NORMAL, 20));
    grid.add(scenetitle, 0, 0, 2, 1);

    Label userName = new Label("User Name:");
    grid.add(userName, 0, 1);

    TextField userTextField = new TextField();
    grid.add(userTextField, 1, 1);

    Label pw = new Label("Password:");
    grid.add(pw, 0, 2);

    PasswordField pwBox = new PasswordField();
    grid.add(pwBox, 1, 2);

    Button btn = new Button("Sign in");
    HBox hbBtn = new HBox(10);
    hbBtn.setAlignment(Pos.BOTTOM_RIGHT);
    hbBtn.getChildren().add(btn);
    grid.add(hbBtn, 1, 4);

    final Text actiontarget = new Text();
    grid.add(actiontarget, 1, 6);

    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            actiontarget.setFill(Color.FIREBRICK);
            actiontarget.setText("Sign in button pressed");
        }
    });

    Scene scene = new Scene(grid, 300, 275);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:com.bdb.weather.display.freeplot.FreePlot.java

/**
 * Create the panel that allows the user to select what series are displayed
 * //from   ww  w .  j  a v a  2s.co  m
 * @param controls The series display controls
 * 
 * @return The JavaFX Node
 */
private Node createDataSelectionPanel(Collection<SeriesGroupControl> controls) {
    BorderPane p = new BorderPane();

    VBox box = new VBox();

    Button b = new Button(LOAD_DATA_BUTTON);
    b.setOnAction((event) -> {
        loadData();
        displayData();
    });
    //b.setActionCommand(LOAD_DATA_BUTTON);
    //b.setAlignmentX(JComponent.LEFT_ALIGNMENT);
    box.getChildren().add(b);

    for (SeriesGroupControl control : controls) {
        Node collectionPanel = control;
        box.getChildren().add(collectionPanel);
    }

    //box.getChildren().add(VBox.createVerticalGlue());

    p.setTop(box);
    p.setCenter(new FlowPane());

    return p;
}

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 a  2 s.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) {
    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  a  v  a2  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();
}

From source file:MediaControl.java

public MediaControl(final MediaPlayer mp) {
    this.mp = mp;
    setStyle("-fx-background-color: #bfc2c7;");
    mediaView = new MediaView(mp);
    Pane mvPane = new Pane() {
    };//ww w  . ja v  a2  s  .  c  o  m
    mvPane.getChildren().add(mediaView);
    mvPane.setStyle("-fx-background-color: black;");
    setCenter(mvPane);
    mediaBar = new HBox();
    mediaBar.setAlignment(Pos.CENTER);
    mediaBar.setPadding(new Insets(5, 10, 5, 10));
    BorderPane.setAlignment(mediaBar, Pos.CENTER);

    final Button playButton = new Button(">");

    playButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent e) {
            Status status = mp.getStatus();

            if (status == Status.UNKNOWN || status == Status.HALTED) {
                // don't do anything in these states
                return;
            }

            if (status == Status.PAUSED || status == Status.READY || status == Status.STOPPED) {
                // rewind the movie if we're sitting at the end
                if (atEndOfMedia) {
                    mp.seek(mp.getStartTime());
                    atEndOfMedia = false;
                }
                mp.play();
            } else {
                mp.pause();
            }
        }
    });
    mp.currentTimeProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            updateValues();
        }
    });

    mp.setOnPlaying(new Runnable() {
        public void run() {
            if (stopRequested) {
                mp.pause();
                stopRequested = false;
            } else {
                playButton.setText("||");
            }
        }
    });

    mp.setOnPaused(new Runnable() {
        public void run() {
            System.out.println("onPaused");
            playButton.setText(">");
        }
    });

    mp.setOnReady(new Runnable() {
        public void run() {
            duration = mp.getMedia().getDuration();
            updateValues();
        }
    });

    mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);
    mp.setOnEndOfMedia(new Runnable() {
        public void run() {
            if (!repeat) {
                playButton.setText(">");
                stopRequested = true;
                atEndOfMedia = true;
            }
        }
    });
    mediaBar.getChildren().add(playButton);
    // Add spacer
    Label spacer = new Label("   ");
    mediaBar.getChildren().add(spacer);

    // Add Time label
    Label timeLabel = new Label("Time: ");
    mediaBar.getChildren().add(timeLabel);

    // Add time slider
    timeSlider = new Slider();
    HBox.setHgrow(timeSlider, Priority.ALWAYS);
    timeSlider.setMinWidth(50);
    timeSlider.setMaxWidth(Double.MAX_VALUE);

    timeSlider.valueProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (timeSlider.isValueChanging()) {
                // multiply duration by percentage calculated by slider position
                mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
            }
        }
    });

    mediaBar.getChildren().add(timeSlider);

    // Add Play label
    playTime = new Label();
    playTime.setPrefWidth(130);
    playTime.setMinWidth(50);
    mediaBar.getChildren().add(playTime);

    // Add the volume label
    Label volumeLabel = new Label("Vol: ");
    mediaBar.getChildren().add(volumeLabel);

    // Add Volume slider
    volumeSlider = new Slider();
    volumeSlider.setPrefWidth(70);
    volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
    volumeSlider.setMinWidth(30);
    volumeSlider.valueProperty().addListener(new InvalidationListener() {
        public void invalidated(Observable ov) {
            if (volumeSlider.isValueChanging()) {
                mp.setVolume(volumeSlider.getValue() / 100.0);
            }
        }
    });
    mediaBar.getChildren().add(volumeSlider);
    setBottom(mediaBar);
}

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 ww  .  j a  v  a2  s .  c o m*/

    final Label label = new Label("Files Transfer:");
    final ProgressIndicator progressIndicator = new ProgressIndicator(0);

    final HBox hb = new HBox();
    hb.setSpacing(5);
    hb.setAlignment(Pos.CENTER);
    hb.getChildren().addAll(label, progressIndicator);
    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);
            progressIndicator.setProgress(0);
            cancelButton.setDisable(false);
            copyWorker = createWorker();

            progressIndicator.progressProperty().unbind();
            progressIndicator.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);
            progressIndicator.progressProperty().unbind();
            progressIndicator.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);//  w w  w. j a v  a2  s  .  c om

    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:pah9qdmoviereviews.MovieReviewsFXMLController.java

public void ready(Stage stage, Scene scene) {
    this.stage = stage;
    this.scene = scene;

    movieReviewManager = new NYTMoviewReviewManager();
    movieReviewManager.addPropertyChangeSupport(((evt) -> {
        switch (evt.getPropertyName()) {
        case "Exception":
            Platform.runLater(() -> displayExceptionAlert((Exception) evt.getNewValue()));
            break;
        case "Add Movie Review":
            Platform.runLater(() -> {
                movieReviews.add((NYTMovieReview) evt.getNewValue());
                this.foundText.setText(("Found " + movieReviews.size() + " results for " + searchString + "."));
            });/*from  w  w w.j  av  a 2 s  .c om*/
            break;
        case "Clear Movie Reviews":
            Platform.runLater(() -> movieReviews.clear());
            break;
        case "Completed":
            if (movieReviews.isEmpty())
                this.foundText.setText("No reviews found for " + searchString);
            break;
        default:
            Platform.runLater(
                    () -> displayExceptionAlert(new Exception("Invalid Property Change Support Property")));
            break;
        }

    }));

    movieReviews = FXCollections.observableArrayList();
    listView.setItems(movieReviews);
    listView.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<NYTMovieReview>() {
        @Override
        public void changed(ObservableValue<? extends NYTMovieReview> observable, NYTMovieReview oldValue,
                NYTMovieReview newValue) {
            detailsBox.getChildren().clear();
            movieImage.setImage(null);
            if (newValue != null) {
                DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
                String pictureLink = newValue.getPictureLink();
                if (pictureLink != null && !pictureLink.isEmpty()) {
                    reviewBox.getChildren().remove(0);
                    reviewBox.getChildren().add(0, movieImage);
                    movieImage.setImage(new Image(pictureLink));
                } else {
                    reviewBox.getChildren().remove(0);
                    reviewBox.getChildren().add(0, missingImageText);
                    movieImage.setImage(null);
                }

                ArrayList<Label> labelArray = new ArrayList<>();
                if (!newValue.getDisplayTitle().isEmpty()) {
                    Label titleLabel = new Label(newValue.getDisplayTitle());
                    titleLabel.fontProperty().set(Font.font(20));
                    labelArray.add(titleLabel);
                }
                if (!newValue.getSummary().isEmpty()) {
                    labelArray.add(new Label("Summary: " + newValue.getSummary()));
                }
                if (!newValue.getMpaaRating().isEmpty()) {
                    labelArray.add(new Label("MPAA Rating: " + newValue.getMpaaRating()));
                }
                if (newValue.getPublicationDate() != null) {
                    labelArray.add(
                            new Label("Publication Date: " + dateFormat.format(newValue.getPublicationDate())));
                }
                if (newValue.getOpeningDate() != null) {
                    labelArray.add(new Label("Opening Date: " + dateFormat.format(newValue.getOpeningDate())));
                }

                labelArray.forEach((label) -> {
                    label.wrapTextProperty().set(true);
                });

                detailsBox.getChildren().addAll(labelArray);

                Button openButton = new Button("Open Review");
                openButton.setOnAction((event) -> {
                    try {
                        Desktop.getDesktop().browse(new URI(newValue.getArticleLink()));
                    } catch (Exception ex) {
                        displayExceptionAlert(ex);
                    }
                });

                detailsBox.getChildren().add(openButton);
            }
        }
    });

    HBox.setMargin(missingImageText, new Insets(15, 15, 15, 15));
    searchTextField.setOnKeyPressed((event) -> {
        if (event.getCode() == KeyCode.ENTER) {
            loadReviews(searchTextField.getText());
        }
    });
    //        searchTextField.textProperty().addListener((observable, oldValue, newValue) -> {
    //            if(newValue != null && !newValue.isEmpty())
    //                loadReviews(newValue);
    //        });
}