Example usage for javafx.scene.control Tab setOnSelectionChanged

List of usage examples for javafx.scene.control Tab setOnSelectionChanged

Introduction

In this page you can find the example usage for javafx.scene.control Tab setOnSelectionChanged.

Prototype

public final void setOnSelectionChanged(EventHandler<Event> value) 

Source Link

Document

Defines a function to be called when a selection changed has occurred on the tab.

Usage

From source file:de.perdoctus.ebikeconnect.gui.MainWindowController.java

private void initActivitiesTab() throws Exception {
    final Parent parent = fxmlLoader.load(getClass().getResourceAsStream("/fxml/ActivitiesOverview.fxml"));
    this.activitiesOverviewController = fxmlLoader.getController();

    final Tab tab = new Tab(rb.getString("activities"));
    tab.setContent(parent);/*from  w  w w . j av a2s  .c om*/
    tabPane.getTabs().add(tab);

    tab.setOnSelectionChanged(event -> {
        if (tab.isSelected()) {
            activitiesOverviewController.reloadHeaders();
        }
    });

    mnuExport.disableProperty()
            .bind(activitiesOverviewController.currentActivityDetailsGroupProperty().isNull());
}

From source file:org.beryx.viewreka.fxapp.Viewreka.java

public void refreshViews() {
    if (project == null)
        return;/*  w  w w .j a va 2s  .c om*/

    project.getProjectSettingsManager().saveSettings();

    viewsTabPane.getTabs().clear();

    ProjectSettings projectSettings = project.getProjectSettingsManager().getSettings();
    String currentViewName = projectSettings.getCurrentView();

    Tab selectedTab = null;
    for (FxView view : project.getViews()) {
        String viewName = view.getName();
        final Tab tab = new Tab(viewName);
        viewsTabPane.getTabs().add(tab);
        if (viewName.equals(currentViewName)) {
            selectedTab = tab;
        }

        final ViewPane<?> viewPane = ViewPane.fromModel(view, projectSettings);
        tab.setContent(viewPane);

        viewPane.autosize();

        tab.setOnSelectionChanged(new EventHandler<Event>() {
            @Override
            public void handle(Event event) {
                viewPane.autosize();
                Tab selTab = viewsTabPane.getSelectionModel().getSelectedItem();
                if (selTab != null) {
                    String selectedView = selTab.getText();
                    projectSettings.setCurrentView(selectedView);
                }
            }
        });
    }

    if (selectedTab != null) {
        viewsTabPane.getSelectionModel().select(selectedTab);
    }
    layout();
}