Example usage for javafx.scene Group Group

List of usage examples for javafx.scene Group Group

Introduction

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

Prototype

public Group() 

Source Link

Document

Constructs a group.

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 450, 250);

    Label notification = new Label();
    notification.setText("Label");

    GridPane grid = new GridPane();
    grid.setVgap(4);/*from www.  ja  v a  2 s  .c o m*/
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(notification, 1, 0);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(grid);
    stage.setScene(scene);
    stage.show();

}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 450, 250);

    TextField notification = new TextField();
    notification.setText("Label");

    notification.clear();//w ww. j a  v a 2  s  . c  o m

    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(notification, 1, 0);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(grid);
    stage.setScene(scene);
    stage.show();

}

From source file:Main.java

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

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);/*from w  w w . j a  v a 2  s.  c o m*/
    gridpane.setVgap(10);

    Label candidatesLbl = new Label("Left");
    GridPane.setHalignment(candidatesLbl, HPos.CENTER);
    gridpane.add(candidatesLbl, 0, 0);

    Label heroesLbl = new Label("Right");
    gridpane.add(heroesLbl, 2, 0);
    GridPane.setHalignment(heroesLbl, HPos.CENTER);

    final ObservableList<String> lefts = FXCollections.observableArrayList("A", "B", "C");
    final ListView<String> leftListView = new ListView<String>(lefts);
    leftListView.setPrefWidth(150);
    leftListView.setPrefHeight(150);

    gridpane.add(leftListView, 0, 1);

    final ObservableList<String> rights = FXCollections.observableArrayList();
    final ListView<String> rightListView = new ListView<String>(rights);
    rightListView.setPrefWidth(150);
    rightListView.setPrefHeight(150);

    gridpane.add(rightListView, 2, 1);

    Button sendRightButton = new Button(">");
    sendRightButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            String item = leftListView.getSelectionModel().getSelectedItem();
            if (item != null) {
                leftListView.getSelectionModel().clearSelection();
                lefts.remove(item);
                rights.add(item);
            }
        }
    });

    Button sendLeftButton = new Button("<");
    sendLeftButton.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            String item = rightListView.getSelectionModel().getSelectedItem();
            if (item != null) {
                rightListView.getSelectionModel().clearSelection();
                rights.remove(item);
                lefts.add(item);
            }
        }
    });

    VBox vbox = new VBox(5);
    vbox.getChildren().addAll(sendRightButton, sendLeftButton);

    gridpane.add(vbox, 1, 1);
    GridPane.setConstraints(vbox, 1, 1, 1, 2, HPos.CENTER, VPos.CENTER);

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

From source file:Main.java

License:asdf

@Override
public void start(Stage primaryStage) {
    User user = new User();
    Group root = new Group();
    Scene scene = new Scene(root, 320, 100);
    primaryStage.setScene(scene);// w ww  .ja v  a 2  s. c  o m

    Text userName = new Text();
    userName.textProperty().bind(user.userNameProperty());

    PasswordField passwordField = new PasswordField();
    passwordField.setPromptText("Password");
    user.passwordProperty().bind(passwordField.textProperty());

    // user hits the enter key
    passwordField.setOnAction(actionEvent -> {
        if (accessGranted.get()) {
            System.out.println("granted access:" + user.getUserName());
            System.out.println("password:" + user.getPassword());
            Platform.exit();
        } else {
            primaryStage.setTitle("no access");
        }
    });

    passwordField.textProperty().addListener((obs, ov, nv) -> {
        boolean granted = passwordField.getText().equals(MY_PASS);
        accessGranted.set(granted);
        if (granted) {
            primaryStage.setTitle("");
        }
    });
    VBox formLayout = new VBox(4);
    formLayout.getChildren().addAll(userName, passwordField);
    formLayout.setLayoutX(12);
    formLayout.setLayoutY(12);

    root.getChildren().addAll(formLayout);
    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 ww w.j a va 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();
}

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  ava2s.  co  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) {
    Group root = new Group();
    Scene scene = new Scene(root, 551, 400);
    scene.setOnDragOver(new EventHandler<DragEvent>() {
        @Override// w  w w  .  j  a  va 2 s .  c o m
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            if (db.hasFiles()) {
                event.acceptTransferModes(TransferMode.COPY);
            } else {
                event.consume();
            }
        }
    });

    // Dropping over surface
    scene.setOnDragDropped(new EventHandler<DragEvent>() {
        @Override
        public void handle(DragEvent event) {
            Dragboard db = event.getDragboard();
            boolean success = false;
            if (db.hasFiles()) {
                success = true;
                String filePath = null;
                for (File file : db.getFiles()) {
                    filePath = file.getAbsolutePath();
                    System.out.println(filePath);
                }
            }
            event.setDropCompleted(success);
            event.consume();
        }
    });

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

From source file:Main.java

@Override
public void start(Stage primaryStage) {

    Button btn = new Button();
    final Label lbl = new Label();

    primaryStage.setTitle("Hello World!");

    lbl.setLayoutX(70);//from w ww.  j  a v  a  2 s .  c om
    lbl.setLayoutY(150);

    btn.setLayoutX(100);
    btn.setLayoutY(100);
    btn.setText("Hello, World!");

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

        @Override
        public void handle(ActionEvent event) {
            lbl.setText("Hello, World.");
        }
    });

    Group root = new Group();

    root.getChildren().add(btn);
    root.getChildren().add(lbl);
    primaryStage.setScene(new Scene(root, 300, 250));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 450, 250);

    ComboBox emailComboBox = new ComboBox();
    emailComboBox.getItems().addAll("A", "B", "C", "D", "E");
    emailComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override/*w w  w.  j a  v a 2s.  co  m*/
        public ListCell<String> call(ListView<String> param) {
            final ListCell<String> cell = new ListCell<String>() {
                {
                    super.setPrefWidth(100);
                }

                @Override
                public void updateItem(String item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null) {
                        setText(item);
                        if (item.contains("A")) {
                            setTextFill(Color.RED);
                        } else if (item.contains("B")) {
                            setTextFill(Color.GREEN);
                        } else {
                            setTextFill(Color.BLACK);
                        }
                    } else {
                        setText(null);
                    }
                }
            };
            return cell;
        }

    });

    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setHgap(10);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("To: "), 0, 0);
    grid.add(emailComboBox, 1, 0);

    Group root = (Group) scene.getRoot();
    root.getChildren().add(grid);
    stage.setScene(scene);
    stage.show();

}

From source file:Main.java

@Override
public void start(Stage stage) {
    stage.setTitle("HTML");
    stage.setWidth(500);/*w w  w. j a v a2  s. com*/
    stage.setHeight(500);
    Scene scene = new Scene(new Group());

    VBox root = new VBox();

    final HTMLEditor htmlEditor = new HTMLEditor();
    htmlEditor.setPrefHeight(600);
    htmlEditor.setHtmlText(INITIAL_TEXT);

    root.getChildren().addAll(htmlEditor);
    scene.setRoot(root);

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