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(String text) 

Source Link

Document

Creates a button with the specified text as its label.

Usage

From source file:TwoButtons.java

public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    final RowLayout layout = new RowLayout();
    shell.setLayout(layout);//from www .  j  a va2s.c om

    /* Create the SWT button */
    final org.eclipse.swt.widgets.Button swtButton =
            new org.eclipse.swt.widgets.Button(shell, SWT.PUSH);
    swtButton.setText("SWT Button");

    /* Create an FXCanvas */
    final FXCanvas fxCanvas = new FXCanvas(shell, SWT.NONE) {

        public Point computeSize(int wHint, int hHint, boolean changed) {
            getScene().getWindow().sizeToScene();
            int width = (int) getScene().getWidth();
            int height = (int) getScene().getHeight();
            return new Point(width, height);
        }
    };
    /* Create a JavaFX Group node */
    Group group = new Group();
    /* Create a JavaFX button */
    final Button jfxButton = new Button("JFX Button");
    /* Assign the CSS ID ipad-dark-grey */
    jfxButton.setId("ipad-dark-grey");
    /* Add the button as a child of the Group node */
    group.getChildren().add(jfxButton);
    /* Create the Scene instance and set the group node as root */
    Scene scene = new Scene(group, Color.rgb(shell.getBackground().getRed(), shell.getBackground().getGreen(),
            shell.getBackground().getBlue()));
    /* Attach an external stylesheet */
    scene.getStylesheets().add("twobuttons/Buttons.css");
    fxCanvas.setScene(scene);

    /* Add Listeners */
    swtButton.addListener(SWT.Selection, new Listener() {

        public void handleEvent(Event event) {
            jfxButton.setText("JFX Button: Hello from SWT");
            shell.layout();
        }
    });
    jfxButton.setOnAction(new EventHandler<ActionEvent>() {

        public void handle(ActionEvent event) {
            swtButton.setText("SWT Button: Hello from JFX");
            shell.layout();
        }
    });

    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    display.dispose();
}

From source file:de.pixida.logtest.designer.commons.SelectFileButton.java

public static Button createButtonWithFileSelection(final TextField inputFieldShowingPath, final String icon,
        final String title, final String fileMask, final String fileMaskDescription) {
    final Button selectLogFileButton = new Button("Select");
    selectLogFileButton.setGraphic(Icons.getIconGraphics(icon));
    selectLogFileButton.setOnAction(event -> {
        final FileChooser fileChooser = new FileChooser();
        fileChooser.setTitle(title);/* w ww .  j a  v  a 2  s.c  om*/
        if (StringUtils.isNotBlank(fileMask) && StringUtils.isNotBlank(fileMaskDescription)) {
            fileChooser.getExtensionFilters()
                    .add(new FileChooser.ExtensionFilter(fileMaskDescription, fileMask));
        }
        File initialDirectory = new File(inputFieldShowingPath.getText().trim());
        if (!initialDirectory.isDirectory()) {
            initialDirectory = initialDirectory.getParentFile();
        }
        if (initialDirectory == null || !initialDirectory.isDirectory()) {
            if (lastFolder != null) {
                initialDirectory = lastFolder;
            } else {
                initialDirectory = new File(".");
            }
        }
        fileChooser.setInitialDirectory(initialDirectory);
        final File selectedFile = fileChooser.showOpenDialog(((Node) event.getTarget()).getScene().getWindow());
        if (selectedFile != null) {
            inputFieldShowingPath.setText(selectedFile.getAbsolutePath());
            final File parent = selectedFile.getParentFile();
            if (parent != null && parent.isDirectory()) {
                lastFolder = parent;
            }
        }
    });
    return selectLogFileButton;
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Button b1 = new Button("Close");

    VBox root = new VBox();
    root.getChildren().addAll(b1);/*from   w  w w .ja va2s . co m*/

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("");
    stage.show();

    System.out.println("b1(layoutBounds)=" + b1.getLayoutBounds());
    System.out.println("b1(boundsInLocal)=" + b1.getBoundsInLocal());
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Button okBtn = new Button("OK");
    Button cancelBtn = new Button("Cancel");

    cancelBtn.setPrefWidth(100);//w  ww  .j a va 2s  .  c  o  m

    VBox root = new VBox();
    root.getChildren().addAll(okBtn, cancelBtn);

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("Overriding Node Sizes");
    stage.show();

}

From source file:Main.java

@Override
public void start(Stage stage) {
    Button okBtn = new Button("OK");
    Button cancelBtn = new Button("Cancel");

    cancelBtn.setPrefWidth(100);/*from   ww  w  .  j  ava  2s .  co m*/

    VBox root = new VBox();
    root.getChildren().addAll(okBtn, cancelBtn);

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("Overriding Node Sizes");
    stage.show();

    System.out.println("okBtn.getPrefWidth(): " + okBtn.getPrefWidth());
    System.out.println("okBtn.getMinWidth(): " + okBtn.getMinWidth());
    System.out.println("okBtn.getMaxWidth(): " + okBtn.getMaxWidth());

    System.out.println("cancelBtn.getPrefWidth(): " + cancelBtn.getPrefWidth());
    System.out.println("cancelBtn.getMinWidth(): " + cancelBtn.getMinWidth());
    System.out.println("cancelBtn.getMaxWidth(): " + cancelBtn.getMaxWidth());
}

From source file:Main.java

@Override
public void start(Stage stage) {
    String yahooURL = "http://www.java2s.com";
    Button openURLButton = new Button("Go!");
    openURLButton.setOnAction(e -> getHostServices().showDocument(yahooURL));

    Scene scene = new Scene(openURLButton);
    stage.setScene(scene);/*from  w  w  w .  j  a  v  a  2  s .  c o  m*/
    stage.setTitle("Knowing the Host");
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {

    Button openURLButton = new Button("Go!");
    openURLButton.setOnAction(e -> {/*from   w w  w .j a v a  2  s  . co m*/
        HostServices host = this.getHostServices();

        System.out.println("CodeBase:" + host.getCodeBase());

        System.out.println("DocumentBase:" + host.getDocumentBase());

        System.out.println("Environment:" + host.getWebContext());

        System.out.println("Splash Image URI" + host.resolveURI(host.getDocumentBase(), "splash.jpg"));
    });

    Scene scene = new Scene(openURLButton);
    stage.setScene(scene);
    stage.setTitle("Knowing the Host");
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Button b1 = new Button("Close");
    b1.setEffect(new DropShadow());

    VBox root = new VBox();
    root.getChildren().addAll(b1);/*from www  .j a  v a2s  .  co m*/

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.setTitle("Testing LayoutBounds");
    stage.show();

}

From source file:Main.java

@Override
public void start(Stage stage) {
    Button exitBtn = new Button("Exit");
    exitBtn.setOnAction(e -> Platform.exit());

    VBox root = new VBox();
    root.getChildren().add(exitBtn);/* ww  w.j  av a2 s  .co  m*/

    Scene scene = new Scene(root, 300, 50);
    stage.setScene(scene);
    stage.setTitle("Hello JavaFX Application with a Scene");
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group group = new Group();

    Button button = new Button("Button");

    button.setStyle("-fx-font-size: 14px;");

    group.getChildren().add(button);//from w  w  w.j  a  v a  2 s  .co  m

    Scene scene = new Scene(group, 300, 200);
    primaryStage.setScene(scene);
    primaryStage.show();
}