Java Code Examples for javafx.scene.control.Tab#setOnSelectionChanged()

The following examples show how to use javafx.scene.control.Tab#setOnSelectionChanged() . 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: MainWindow.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
private Tab createContainersTab(ContainersFeaturePanel containers) {
    final Tab containersTab = new Tab(tr("Containers"), containers);

    containersTab.setClosable(false);

    containersTab.setOnSelectionChanged(event -> containers.getContainersManager().fetchContainers(
            containerCategories -> Platform.runLater(() -> {
                containers.getCategories().setAll(containerCategories);
                containers.setInitialized(true);
            }),
            e -> Platform.runLater(() -> {
                final ErrorDialog errorDialog = ErrorDialog.builder()
                        .withMessage(tr("Loading containers failed."))
                        .withException(e)
                        .withOwner(containers.getScene().getWindow())
                        .build();

                errorDialog.showAndWait();
            })));

    return containersTab;
}
 
Example 2
Source File: TabController.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private void configureTab(Tab tab, String title, String iconPath, AnchorPane containerPane, URL resourceURL, EventHandler<Event> onSelectionChangedEvent) {
    double imageWidth = 40.0;

    ImageView imageView = new ImageView(new Image(iconPath));
    imageView.setFitHeight(imageWidth);
    imageView.setFitWidth(imageWidth);

    Label label = new Label(title);
    label.setMaxWidth(tabWidth - 20);
    label.setPadding(new Insets(5, 0, 0, 0));
    label.setStyle("-fx-text-fill: black; -fx-font-size: 10pt; -fx-font-weight: bold;");
    label.setTextAlignment(TextAlignment.CENTER);

    BorderPane tabPane = new BorderPane();
    tabPane.setRotate(90.0);
    tabPane.setMaxWidth(tabWidth);
    tabPane.setCenter(imageView);
    tabPane.setBottom(label);

    tab.setText("");
    tab.setGraphic(tabPane);

    tab.setOnSelectionChanged(onSelectionChangedEvent);

    if (containerPane != null && resourceURL != null) {
        try {
            Parent contentView = FXMLLoader.load(resourceURL);
            containerPane.getChildren().add(contentView);
            AnchorPane.setTopAnchor(contentView, 0.0);
            AnchorPane.setBottomAnchor(contentView, 0.0);
            AnchorPane.setRightAnchor(contentView, 0.0);
            AnchorPane.setLeftAnchor(contentView, 0.0);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}