Java Code Examples for javafx.scene.Scene#getRoot()

The following examples show how to use javafx.scene.Scene#getRoot() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Renderer.java    From strangefx with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void renderMeasuredProbabilities(int[] results) {
    CategoryAxis xAxis = new CategoryAxis();
    NumberAxis yAxis = new NumberAxis();
    BarChart<String, Integer> barChart = new BarChart(xAxis, yAxis);
    barChart.setData(getChartData(results));
    barChart.setTitle("Measured probability distribution");
    StackPane root = new StackPane();
    root.getChildren().add(barChart);
    if (myStage != null) {
        Scene oldscene = myStage.getScene();
        VBox box = (VBox)(oldscene.getRoot());
        oldscene.setRoot(new StackPane());
        box.getChildren().add(root);
        Scene newScene = new Scene(box);
        newScene.getStylesheets().add(Main.class.getResource("/styles.css").toExternalForm());
        myStage.setScene(newScene);
    } else {
        Stage stage = new Stage();
        stage.setScene(new Scene(root, 640, 480));
        stage.show();
    }

}
 
Example 2
Source File: WindowsMenu.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add the Windows menu
 */
public static void addWindowsMenu(final Scene scene) {
  Parent rootNode = scene.getRoot();
  if (rootNode instanceof Pane) {
    Pane rootPane = (Pane) rootNode;
    MenuBar menuBar = new MenuBar();
    menuBar.setUseSystemMenuBar(true);
    menuBar.getMenus().add(new WindowsMenu());
    rootPane.getChildren().add(menuBar);
  }
}
 
Example 3
Source File: AppUtils.java    From java-ml-projects with Apache License 2.0 5 votes vote down vote up
public static <T extends Object> void doBlockingAsyncWork(Scene scene, Supplier<T> action, Consumer<T> success,
		Consumer<Throwable> error) {
	Parent originalRoot = scene.getRoot();
	Runnable blockScreen = () -> originalRoot.setDisable(true);
	Runnable unblockScreen = () -> originalRoot.setDisable(false);

	Task<T> task = new Task<T>() {
		@Override
		protected T call() throws Exception {
			blockScreen.run();
			return action.get();
		}

		@Override
		protected void succeeded() {
			unblockScreen.run();
			success.accept(getValue());
		}

		@Override
		protected void failed() {
			unblockScreen.run();
			error.accept(getException());
		}
	};
	Thread t = new Thread(task);
	t.setDaemon(true);
	t.start();
}
 
Example 4
Source File: ComboBoxSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    stage.setTitle("ComboBoxSample");
    Scene scene = new Scene(new Group(), 500, 270);

    final ComboBox emailComboBox = new ComboBox();
    emailComboBox.getItems().addAll("[email protected]", "[email protected]", "[email protected]",
            "[email protected]", "[email protected]");

    emailComboBox.setPromptText("Email address");
    emailComboBox.setEditable(true);
    emailComboBox.setOnAction((Event ev) -> {
        address = emailComboBox.getSelectionModel().getSelectedItem().toString();
    });

    final ComboBox priorityComboBox = new ComboBox();
    priorityComboBox.getItems().addAll("Highest", "High", "Normal", "Low", "Lowest");
    priorityComboBox.setValue("Normal");
    priorityComboBox.setCellFactory(new Callback<ListView<String>, ListCell<String>>() {
        @Override
        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("High")) {
                            setTextFill(Color.RED);
                        } else if (item.contains("Low")) {
                            setTextFill(Color.GREEN);
                        } else {
                            setTextFill(Color.BLACK);
                        }
                    } else {
                        setText(null);
                    }
                }
            };
            return cell;
        }

    });

    button.setOnAction((ActionEvent e) -> {
        if (emailComboBox.getValue() != null && !emailComboBox.getValue().toString().isEmpty()) {
            notification.setText("Your message was successfully sent" + " to " + address);
            emailComboBox.setValue(null);
            if (priorityComboBox.getValue() != null && !priorityComboBox.getValue().toString().isEmpty()) {
                priorityComboBox.setValue(null);
            }
            subject.clear();
            text.clear();
        } else {
            notification.setText("You have not selected a recipient!");
        }
    });

    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);
    grid.add(new Label("Priority: "), 2, 0);
    grid.add(priorityComboBox, 3, 0);
    grid.add(new Label("Subject: "), 0, 1);
    grid.add(subject, 1, 1, 3, 1);
    grid.add(text, 0, 2, 4, 1);
    grid.add(button, 0, 3);
    grid.add(notification, 1, 3, 3, 1);

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

}
 
Example 5
Source File: TitledPaneSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public void start(Stage stage) {
    stage.setTitle("TitledPane");
    Scene scene = new Scene(new Group(), 450, 250);

    TitledPane gridTitlePane = new TitledPane();
    GridPane grid = new GridPane();
    grid.setVgap(4);
    grid.setPadding(new Insets(5, 5, 5, 5));
    grid.add(new Label("First Name: "), 0, 0);
    grid.add(new TextField(), 1, 0);
    grid.add(new Label("Last Name: "), 0, 1);
    grid.add(new TextField(), 1, 1);
    grid.add(new Label("Email: "), 0, 2);
    grid.add(new TextField(), 1, 2);
    grid.add(new Label("Attachment: "), 0, 3);
    grid.add(label, 1, 3);
    gridTitlePane.setText("Grid");
    gridTitlePane.setContent(grid);

    final Accordion accordion = new Accordion();

    for (int i = 0; i < imageNames.length; i++) {
        images[i] = new Image(getClass().getResourceAsStream(imageNames[i] + ".jpg"));
        pics[i] = new ImageView(images[i]);
        tps[i] = new TitledPane(imageNames[i], pics[i]);
    }
    accordion.getPanes().addAll(tps);

    accordion.expandedPaneProperty()
            .addListener((ObservableValue<? extends TitledPane> ov, TitledPane old_val, TitledPane new_val) -> {
                if (new_val != null) {
                    label.setText(accordion.getExpandedPane().getText() + ".jpg");
                }
            });

    HBox hbox = new HBox(10);
    hbox.setPadding(new Insets(20, 0, 0, 20));
    hbox.getChildren().setAll(gridTitlePane, accordion);

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