Example usage for javafx.scene Group getChildren

List of usage examples for javafx.scene Group getChildren

Introduction

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

Prototype

@Override
public ObservableList<Node> getChildren() 

Source Link

Document

Gets the list of children of this Group .

Usage

From source file:Main.java

@Override
public void start(Stage stage) {
    final Group group = new Group();
    Scene scene = new Scene(group, 300, 150);
    stage.setScene(scene);//from w w w  . java2  s.c  o  m
    stage.setTitle("Sample");

    Task<Void> task = new Task<Void>() {
        @Override
        protected Void call() throws Exception {
            for (int i = 0; i < 10; i++) {
                if (isCancelled())
                    break;
                final Rectangle r = new Rectangle(10, 10);
                r.setX(10 * i + i);
                Platform.runLater(new Runnable() {
                    @Override
                    public void run() {
                        group.getChildren().add(r);
                    }
                });
            }
            return null;
        }
    };
    task.run();
    System.out.println(task.getMessage());

    stage.show();
}

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();

    Menu menu = new Menu("File");
    menu.getItems().add(new MenuItem("New"));
    menu.getItems().add(new MenuItem("Save"));
    menu.getItems().add(new SeparatorMenuItem());
    menu.getItems().add(new MenuItem("Exit"));

    CustomMenuItem customMenuItem = new CustomMenuItem(new Slider());
    customMenuItem.setHideOnClick(false);
    menu.getItems().add(customMenuItem);

    menuBar.getMenus().add(menu);//from  ww  w. j  a va 2s .c  om

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

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

From source file:Main.java

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

    GridPane gridpane = new GridPane();
    gridpane.setPadding(new Insets(5));
    gridpane.setHgap(10);/*  www . ja  v  a  2s. com*/
    gridpane.setVgap(10);

    final TextArea cssEditorFld = new TextArea();
    cssEditorFld.setPrefRowCount(10);
    cssEditorFld.setPrefColumnCount(100);
    cssEditorFld.setWrapText(true);
    cssEditorFld.setPrefWidth(150);
    GridPane.setHalignment(cssEditorFld, HPos.CENTER);
    gridpane.add(cssEditorFld, 0, 1);

    String cssDefault = "line1;\nline2;\n";

    cssEditorFld.setText(cssDefault);

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

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    System.out.println(menu.isShowing());

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }//from   w  ww. ja  v  a  2  s  . c om
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();
    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());

    Menu menu = new Menu("File");
    System.out.println(menu.showingProperty());

    MenuItem newItem = new MenuItem("New", null);
    newItem.setOnAction(new EventHandler<ActionEvent>() {
        public void handle(ActionEvent event) {
            System.out.println("Action");
        }/*from  w w  w. j  a va  2  s  . c o m*/
    });

    menu.getItems().add(newItem);
    menu.getItems().add(new SeparatorMenuItem());

    menuBar.getMenus().add(menu);
    root.getChildren().add(menuBar);
    primaryStage.setScene(scene);
    primaryStage.show();
}

From source file:Main.java

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

    final CategoryAxis xAxis = new CategoryAxis();
    final NumberAxis yAxis = new NumberAxis();

    xAxis.setLabel("Month");
    yAxis.setLabel("Value");

    final AreaChart<String, Number> areaChart = new AreaChart<String, Number>(xAxis, yAxis);

    areaChart.setTitle("AreaChart");
    XYChart.Series series = new XYChart.Series();
    series.setName("XYChart.Series");

    series.getData().add(new XYChart.Data("January", 100));
    series.getData().add(new XYChart.Data("February", 200));
    series.getData().add(new XYChart.Data("March", 50));

    areaChart.getData().add(series);/*from ww  w  .  ja  v a  2  s  . co m*/

    root.getChildren().add(areaChart);

    primaryStage.setScene(new Scene(root, 500, 400));
    primaryStage.show();
}

From source file:Main.java

@Override
public void start(Stage primaryStage) {
    Group g = new Group();
    Scene scene = new Scene(g, 550, 250);

    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);

    accordion.expandedPaneProperty()/*w  ww .j a v a  2s.c  om*/
            .addListener((ObservableValue<? extends TitledPane> ov, TitledPane old_val, TitledPane new_val) -> {
                if (new_val != null) {
                    System.out.println(accordion.getExpandedPane().getText());
                }
            });

    g.getChildren().add(accordion);

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

From source file:Main.java

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

    MenuBar menuBar = new MenuBar();

    Menu menu = new Menu("Radio Button Menu Item");
    ToggleGroup tGroup = new ToggleGroup();
    RadioMenuItem soundAlarmItem = RadioMenuItemBuilder.create().toggleGroup(tGroup).text("On").build();
    RadioMenuItem stopAlarmItem = RadioMenuItemBuilder.create().toggleGroup(tGroup).text("Off").selected(true)
            .build();//from   w  w w  . j  a  v a 2 s  . co m

    menu.getItems().add(soundAlarmItem);
    menu.getItems().add(stopAlarmItem);

    menuBar.prefWidthProperty().bind(primaryStage.widthProperty());
    menuBar.getMenus().add(menu);

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

From source file:Main.java

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

    Button buttonLoad = new Button("Load");
    buttonLoad.setOnAction(new EventHandler<ActionEvent>() {
        @Override//w  ww.j a v a 2s. c o  m
        public void handle(ActionEvent arg0) {
            FileChooser fileChooser = new FileChooser();
            FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("TXT files (*.txt)",
                    "*.txt");
            fileChooser.getExtensionFilters().add(extFilter);
            File file = fileChooser.showOpenDialog(primaryStage);
            System.out.println(file);
        }
    });
    VBox vBox = VBoxBuilder.create().children(buttonLoad).build();
    root.getChildren().add(vBox);
    primaryStage.setScene(new Scene(root, 500, 400));
    primaryStage.show();
}

From source file:Main.java

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

    TextField textBox = new TextField();
    textBox.setPromptText("Write here");
    // Define an event filter
    EventHandler filter = new EventHandler<InputEvent>() {
        public void handle(InputEvent event) {
            System.out.println("Filtering out event " + event.getEventType());
            event.consume();/*from w  ww . j a  v a  2s .  c om*/
        }
    };
    // Register the same filter for two different nodes
    scene.addEventFilter(MouseEvent.MOUSE_PRESSED, filter);

    // Register the filter for another event type
    scene.addEventFilter(KeyEvent.KEY_PRESSED, filter);

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