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:Main.java

@Override
public void start(Stage stage) {
    Label nameLbl = new Label("Enter your name:");
    TextField nameFld = new TextField();

    Label msg = new Label();

    Button sayHelloBtn = new Button("Say Hello");

    sayHelloBtn.setOnAction(e -> {// w  w  w .  j  av  a 2s  .  c o m
        String name = nameFld.getText();
        if (name.trim().length() > 0) {
            msg.setText("Hello " + name);
        } else {
            msg.setText("Hello there");
        }
    });

    VBox root = new VBox();

    root.setSpacing(5);

    root.getChildren().addAll(nameLbl, nameFld, msg, sayHelloBtn);

    Scene scene = new Scene(root, 350, 150);
    stage.setScene(scene);
    stage.setTitle("hi");
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    HBox hbox = new HBox();
    Button button1 = new Button("Add");
    Button button2 = new Button("Remove");
    HBox.setHgrow(button1, Priority.ALWAYS);
    HBox.setHgrow(button2, Priority.ALWAYS);
    button1.setMaxWidth(Double.MAX_VALUE);
    button2.setMaxWidth(Double.MAX_VALUE);
    hbox.getChildren().addAll(button1, button2);

    hbox.setPrefWidth(400);/*  w w w. jav  a  2  s.  c om*/

    System.out.println(hbox.spacingProperty());

    root.getChildren().add(hbox);
    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, 300, 250, Color.WHITE);

    HBox hbox = new HBox();
    Button button1 = new Button("Add");
    Button button2 = new Button("Remove");
    HBox.setHgrow(button1, Priority.ALWAYS);
    HBox.setHgrow(button2, Priority.ALWAYS);
    button1.setMaxWidth(Double.MAX_VALUE);
    button2.setMaxWidth(Double.MAX_VALUE);
    hbox.getChildren().addAll(button1, button2);

    hbox.setPrefWidth(400);/*ww  w .ja v  a2 s.co  m*/

    hbox.setSpacing(10);

    root.getChildren().add(hbox);
    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, 300, 250, Color.WHITE);

    HBox hbox = new HBox();
    Button button1 = new Button("Add");
    Button button2 = new Button("Remove");
    HBox.setHgrow(button1, Priority.ALWAYS);
    HBox.setHgrow(button2, Priority.ALWAYS);
    button1.setMaxWidth(Double.MAX_VALUE);
    button2.setMaxWidth(Double.MAX_VALUE);
    hbox.getChildren().addAll(button1, button2);

    hbox.setPrefWidth(400);//from ww w. ja  v  a2  s.  co m

    HBox.setMargin(button1, new Insets(1, 1, 1, 1));

    root.getChildren().add(hbox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    HBox hbox = new HBox();
    Button button1 = new Button("Add               ");
    Button button2 = new Button("Remove   ");
    HBox.setHgrow(button1, Priority.ALWAYS);
    HBox.setHgrow(button2, Priority.ALWAYS);
    button1.setMaxWidth(Double.MAX_VALUE);
    button2.setMaxWidth(Double.MAX_VALUE);
    hbox.getChildren().addAll(button1, button2);

    hbox.setPrefWidth(400);// w ww. j a  v  a2s. c  o  m

    root.getChildren().add(hbox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    HBox hbox = new HBox();
    Button button1 = new Button("Add");
    Button button2 = new Button("Remove");
    HBox.setHgrow(button1, Priority.ALWAYS);
    HBox.setHgrow(button2, Priority.ALWAYS);
    button1.setMaxWidth(Double.MAX_VALUE);
    button2.setMaxWidth(Double.MAX_VALUE);
    hbox.getChildren().addAll(button1, button2);

    hbox.setPrefWidth(400);/*from w  ww.  j a  v  a2 s.c  o m*/

    System.out.println(hbox.getAlignment());

    root.getChildren().add(hbox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    HBox hbox = new HBox();
    Button button1 = new Button("Add");
    Button button2 = new Button("Remove");
    HBox.setHgrow(button1, Priority.ALWAYS);
    HBox.setHgrow(button2, Priority.ALWAYS);
    button1.setMaxWidth(Double.MAX_VALUE);
    button2.setMaxWidth(Double.MAX_VALUE);
    hbox.getChildren().addAll(button1, button2);

    hbox.setPrefWidth(400);/*  w  w  w  . j a va 2s.c  o m*/

    System.out.println(hbox.getContentBias());

    root.getChildren().add(hbox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("");
    Group root = new Group();
    Scene scene = new Scene(root, 300, 250, Color.WHITE);

    HBox hbox = new HBox(8);//space
    Button button1 = new Button("Add               ");
    Button button2 = new Button("Remove   ");
    HBox.setHgrow(button1, Priority.ALWAYS);
    HBox.setHgrow(button2, Priority.ALWAYS);
    button1.setMaxWidth(Double.MAX_VALUE);
    button2.setMaxWidth(Double.MAX_VALUE);
    hbox.getChildren().addAll(button1, button2);

    hbox.setPrefWidth(400);/*from  w ww .ja va 2 s. co  m*/

    root.getChildren().add(hbox);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    BorderPane root = new BorderPane();
    Scene scene = new Scene(root, 180, 250);

    String[] keys = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#" };

    GridPane numPad = new GridPane();
    for (int i = 0; i < 12; i++) {
        Button button = new Button(keys[i]);
        button.getStyleClass().add("num-button");
        numPad.add(button, i % 3, (int) Math.ceil(i / 3));
    }//from   w  w  w  . j a  v  a2  s.co m

    Button call = new Button("Call");
    call.setId("call-button");
    call.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
    numPad.add(call, 0, 4);

    GridPane.setColumnSpan(call, 3);
    GridPane.setHgrow(call, Priority.ALWAYS);

    root.setCenter(numPad);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    primaryStage.setTitle("Text Fonts");

    Group g = new Group();
    Scene scene = new Scene(g, 550, 250, Color.web("0x0000FF", 1.0));

    TitledPane t1 = new TitledPane("T1", new Button("B1"));
    TitledPane t2 = new TitledPane("T2", new Button("B2"));
    TitledPane t3 = new TitledPane("T3", new Button("B3"));
    Accordion accordion = new Accordion();
    accordion.getPanes().addAll(t1, t2, t3);

    g.getChildren().add(accordion);/*from  w w w .  j  a v a  2 s . c  om*/

    primaryStage.setScene(scene);
    primaryStage.show();
}