Example usage for javafx.scene.control Button Button

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

Introduction

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

Prototype

public Button() 

Source Link

Document

Creates a button with an empty string for its label.

Usage

From source file:dpfmanager.shell.interfaces.gui.fragment.wizard.Wizard1Fragment.java

private void addCheckBox(String id, String name, String path, boolean selected, boolean delete) {
    HBox hbox = new HBox();
    hbox.setAlignment(Pos.CENTER_LEFT);/*www.ja va2  s . c  o m*/

    CheckBox chk = new CheckBox(name);
    chk.setId(id);
    chk.getStyleClass().add("checkreport");
    chk.setSelected(selected);
    chk.setEllipsisString(" ... ");
    chk.setTextOverrun(OverrunStyle.CENTER_ELLIPSIS);
    chk.setTooltip(new Tooltip(path));
    hbox.getChildren().add(chk);

    // EDIT
    Button edit = new Button();
    edit.getStyleClass().addAll("edit-img", "action-img-16");
    edit.setCursor(Cursor.HAND);
    edit.setOnMouseClicked(new EventHandler<MouseEvent>() {
        @Override
        public void handle(MouseEvent event) {
            String iso = chk.getId();
            String path = null;
            if (iso.startsWith("external")) {
                iso = chk.getText();
                path = iso;
            } else if (chk.getId().startsWith("config")) {
                iso = chk.getId().replace("config", "");
                path = DPFManagerProperties.getIsosDir() + "/" + iso;
            }
            controller.editIso(iso, path);
        }
    });
    hbox.getChildren().add(edit);
    HBox.setMargin(edit, new Insets(0, 0, 0, 10));

    // DELETE
    if (delete) {
        Button icon = new Button();
        icon.getStyleClass().addAll("delete-img", "action-img-16");
        icon.setCursor(Cursor.HAND);
        icon.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if (chk.getId().startsWith("external")) {
                    // Only from gui
                    vboxRadios.getChildren().remove(hbox);
                } else if (chk.getId().startsWith("config")) {
                    // From system
                    String name = chk.getId().replace("config", "");
                    File file = new File(DPFManagerProperties.getIsosDir() + "/" + name);
                    if (file.exists() && file.isFile() && acceptDelete(file)) {
                        file.delete();
                        vboxRadios.getChildren().remove(hbox);
                    }
                }
            }
        });
        hbox.getChildren().add(icon);
        HBox.setMargin(icon, new Insets(0, 0, 0, 10));
    }

    vboxRadios.getChildren().add(hbox);
}

From source file:fruitproject.FruitProject.java

public void second(final String pfname) {

    final Stage st = new Stage();
    Scene scene = null;/*  www  .  ja v a 2  s.  c o m*/
    final GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));
    TableView tv = new TableView();

    final TableColumn<Map, String> firstDataColumn = new TableColumn<>("Name");
    final TableColumn<Map, String> secondDataColumn = new TableColumn<>("Amount");
    final TableColumn<Map, String> thirdDataColumn = new TableColumn<>("Remove");
    firstDataColumn.setMinWidth(130);
    secondDataColumn.setMinWidth(130);
    thirdDataColumn.setMinWidth(130);

    if (!pfname.equals("")) {

        firstDataColumn.setCellValueFactory(new MapValueFactory(Column1MapKey));
        secondDataColumn.setCellValueFactory(new MapValueFactory(Column2MapKey));
        thirdDataColumn.setCellValueFactory(new MapValueFactory(Column3MapKey));

        rows = 0;
        tv = new TableView<>(generateDataInMap(pfname, addPairs));

    }

    tv.getColumns().setAll(firstDataColumn, secondDataColumn, thirdDataColumn);

    // secondDataColumn.setCellFactory(TextFieldTableCell.forTableColumn());

    ScrollPane sp = new ScrollPane();
    sp.setMinWidth(400);
    sp.setHbarPolicy(ScrollBarPolicy.NEVER);
    sp.setContent(tv);
    grid.add(sp, 0, 3);

    final ComboBox comboBox = new ComboBox();
    HBox hb1 = new HBox();
    comboBox.setValue("FILE");
    comboBox.getItems().addAll("Save this file", "Load a new file");
    Button btnOk = new Button();
    btnOk.setText("OK");
    hb1.getChildren().addAll(comboBox, btnOk);
    hb1.setSpacing(10);
    grid.add(hb1, 0, 1);

    Label label1 = new Label("Title:");
    final TextField tfFilename = new TextField();
    tfFilename.setText(getTitle(pfname));
    HBox hb = new HBox();
    hb.getChildren().addAll(label1, tfFilename);
    hb.setSpacing(10);
    grid.add(hb, 0, 2);

    final Stage ps = new Stage();
    final TableView tv1 = tv;
    btnOk.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");

            if (comboBox.getValue().equals("Load a new file")) {
                first(ps);
                st.close();
            } else {
                PrintWriter pw = null;
                try {
                    pw = new PrintWriter("abc.json");
                    BufferedWriter bw = new BufferedWriter(new FileWriter(pfname, false));
                    bw.write("{title:\"" + tfFilename.getText() + "\"");
                    bw.write(",fruits:[");
                    for (int i = 0; i < rows; i++) {
                        bw.write("{name:\"" + String.valueOf(firstDataColumn.getCellData(i)) + "\",amount:"
                                + String.valueOf(secondDataColumn.getCellData(i)) + "}");
                        if (i != rows - 1)
                            bw.write(",");
                    }
                    bw.write("]}");

                    bw.close();

                } catch (Exception e) {
                    System.out.println(e.toString());
                }

            }
        }
    });

    Button btn = new Button();
    btn.setText("New Fruit");
    grid.add(btn, 1, 2);

    // TableView tv=new TableView();
    // TableColumn Col1 = new TableColumn("Name");
    // TableColumn Col2 = new TableColumn("Amount");
    // TableColumn Col3 = new TableColumn("Remove");
    // tv.getColumns().addAll(Col1, Col2, Col3);

    //sp.setFitToWidth(true);

    Image img = new Image("file:music.jpg");
    ImageView iv2 = new ImageView();
    iv2.setImage(img);
    iv2.setFitWidth(200);
    iv2.setPreserveRatio(true);
    iv2.setSmooth(true);
    iv2.setCache(true);
    grid.add(iv2, 1, 3);

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

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");

            System.out.println(comboBox.valueProperty());
            st.close();
            third(pfname);

        }
    });

    scene = new Scene(grid, 700, 450);
    st.setScene(scene);
    st.show();

}

From source file:photobooth.views.ExplorerPane.java

private void addXButton() throws IOException {
    Button button = new Button();
    button.setGraphic(//from ww  w. j av a2s  .c o m
            new ImageView(new Image(getClass().getResource("/photobooth/images/exit.png").openStream())));
    button.setStyle("-fx-background-color: transparent;");
    button.setLayoutX(730);
    button.setLayoutY(10);
    button.setMaxSize(50, 50);
    button.setMinSize(50, 50);
    button.getStyleClass().add("blueButton");
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Global.getInstance().setSceneRoot(HomePane.getInstance());
        }
    });
}

From source file:org.sleuthkit.autopsy.timeline.ui.detailview.EventNodeBase.java

/**
 * Install whatever buttons are visible on hover for this node. likes
 * tooltips, this had a surprisingly large impact on speed of loading the
 * chart/*  ww w. j a v  a2  s. c  om*/
 */
void installActionButtons() {
    if (pinButton == null) {
        pinButton = new Button();
        controlsHBox.getChildren().add(pinButton);
        configureActionButton(pinButton);
    }
}

From source file:photobooth.views.ExplorerPane.java

private void addUpButton() throws IOException {
    Button button = new Button();
    button.setGraphic(/*  w w  w .  java2  s  . c o  m*/
            new ImageView(new Image(getClass().getResource("/photobooth/images/up.png").openStream())));
    button.setStyle("-fx-background-color: transparent;");
    button.setMaxSize(50, 50);
    button.setMinSize(50, 50);
    button.setLayoutX(120);
    button.setLayoutY(10);
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Global.getInstance().setSceneRoot(LoadingPane.getInstance());

            Platform.runLater(() -> {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        ExplorerPane.getInstance().setDir(new File(dir).getParentFile().getAbsolutePath(), 0,
                                limit, directoryLevel - 1);
                        Global.getInstance().setSceneRoot(ExplorerPane.getInstance());
                    }
                }).start();
            });

        }
    });

}

From source file:com.panemu.tiwulfx.control.skin.LookupFieldSkin.java

private void initialize() {
    textField = new TextField();
    textField.setFocusTraversable(true);
    textField.setEditable(!lookupField.getDisableManualInput());
    textField.focusedProperty().addListener(new ChangeListener<Boolean>() {
        @Override//from www . j  a va 2 s . c o m
        public void changed(ObservableValue<? extends Boolean> ov, Boolean t, Boolean hasFocus) {
            textField.selectEnd();
        }
    });

    button = new Button();
    button.setFocusTraversable(false);
    button.setGraphic(TiwulFXUtil.getGraphicFactory().createLookupGraphic());
    StackPane.setAlignment(textField, Pos.CENTER_LEFT);
    StackPane.setAlignment(button, Pos.CENTER_RIGHT);
    this.getChildren().addAll(textField, button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent t) {
            if (!lookupField.isFocused()) {
                /**
                 * Need to make this control become focused. Otherwise
                 * changing value in LookupColumn while the LookuField cell
                 * editor
                 * is not focused before, won't trigger commitEdit()
                 */
                lookupField.requestFocus();
            }
            getSkinnable().showLookupDialog();
        }
    });
    updateTextField();
    lookupField.valueProperty().addListener(new ChangeListener() {
        @Override
        public void changed(ObservableValue ov, Object t, Object t1) {
            updateTextField();
        }
    });

    lookupField.markInvalidProperty().addListener(new ChangeListener<Boolean>() {
        @Override
        public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
            if (oldValue && !newValue && needValidation) {
                validate();
            }
        }
    });

    textField.textProperty().addListener(new InvalidationListener() {
        @Override
        public void invalidated(Observable o) {
            if (detectTextChanged) {
                if (waitTimer != null) {
                    loaderTimerTask.setObsolete(true);
                    waitTimer.cancel();
                    waitTimer.purge();
                }

                if (textField.getText() == null || textField.getText().trim().isEmpty()) {
                    lookupField.setValue(null);
                    return;
                }
                lookupField.markInvalidProperty().set(true);
                needValidation = true;

                if (lookupField.getShowSuggestionWaitTime() >= 0) {
                    waitTimer = new Timer("lookupTimer");
                    loaderTimerTask = new LoaderTimerTask(waitTimer);
                    waitTimer.schedule(loaderTimerTask, lookupField.getShowSuggestionWaitTime());
                }
            }
        }
    });

}

From source file:photobooth.views.ExplorerPane.java

private void addNextButton() throws IOException {
    Button button = new Button();
    button.setGraphic(/*  www  . j  a  va  2 s  .  c om*/
            new ImageView(new Image(getClass().getResource("/photobooth/images/next.png").openStream())));
    button.setStyle("-fx-background-radius: 50%; ");
    button.setStyle("-fx-background-color: transparent;");
    button.setLayoutX(740);
    button.setLayoutY(220);
    button.setMaxSize(50, 50);
    button.setMinSize(50, 50);
    this.getChildren().add(button);
    button.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            Global.getInstance().setSceneRoot(LoadingPane.getInstance());
            Platform.runLater(() -> {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        ExplorerPane.getInstance().setDir(dir, offset + limit, limit, directoryLevel);
                        Global.getInstance().setSceneRoot(ExplorerPane.getInstance());
                    }
                }).start();
            });
        }
    });
}

From source file:AudioPlayer3.java

private Button createOpenButton() {
    final Button openButton = new Button();
    openButton.setId("openButton");
    openButton.setOnAction(new OpenHandler());
    openButton.setPrefWidth(32);/*www .java 2  s . c o m*/
    openButton.setPrefHeight(32);
    return openButton;
}

From source file:fruitproject.FruitProject.java

public void third(final String pfname) {
    final Stage st = new Stage();
    GridPane grid = new GridPane();
    grid.setAlignment(Pos.CENTER);//from  w ww.java 2 s  .  co  m
    grid.setHgap(10);
    grid.setVgap(10);
    grid.setPadding(new Insets(25, 25, 25, 25));

    Label label1 = new Label("New Fruit");
    grid.add(label1, 1, 0);
    final TextField txtName = new TextField();
    grid.add(txtName, 1, 1);
    final TextField txtAmount = new TextField();
    grid.add(txtAmount, 1, 2);
    Button btn = new Button();
    btn.setText("OK");
    grid.add(btn, 1, 3);
    btn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            //System.out.println("Hello World!");
            addPairs.add(txtName.getText());
            addPairs.add(txtAmount.getText());
            st.close();
            second(pfname);
        }
    });

    Scene scene = new Scene(grid, 500, 500);
    st.setScene(scene);
    st.show();

}

From source file:AudioPlayer3.java

private Node createControlPanel() {
    final HBox hbox = new HBox();
    hbox.setAlignment(Pos.CENTER);/*from   ww w. ja v  a2s. co m*/
    hbox.setFillHeight(false);

    final Button playPauseButton = createPlayPauseButton();

    final Button seekStartButton = new Button();
    seekStartButton.setId("seekStartButton");
    seekStartButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            seekAndUpdatePosition(Duration.ZERO);
        }
    });

    final Button seekEndButton = new Button();
    seekEndButton.setId("seekEndButton");
    seekEndButton.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            final MediaPlayer mediaPlayer = songModel.getMediaPlayer();
            final Duration totalDuration = mediaPlayer.getTotalDuration();
            final Duration oneSecond = Duration.seconds(1);
            seekAndUpdatePosition(totalDuration.subtract(oneSecond));
        }
    });

    hbox.getChildren().addAll(seekStartButton, playPauseButton, seekEndButton);
    return hbox;
}