How to add Scroll Pane into tabs


Question

I have this simple example of JavaFX tabs

primaryStage.setTitle("Tabs Test");
        Group root = new Group();
        Scene scene = new Scene(root, 600, 500, Color.WHITE);

        TabPane tabPane = new TabPane();
        BorderPane mainPane = new BorderPane();

        //Create Tabs
        Tab tabA = new Tab();
        tabA.setText("Main Component");
        //Add something in Tab
        StackPane tabA_stack = new StackPane();
        tabA_stack.setAlignment(Pos.CENTER);
        tabA_stack.getChildren().add(new Label("Label@Tab B")); 
        tabA.setContent(tabA_stack);
        tabPane.getTabs().add(tabA);

        Tab tabB = new Tab();
        tabB.setText("Second Component");
        //Add something in Tab
        StackPane tabB_stack = new StackPane();
        tabB_stack.setAlignment(Pos.CENTER);
        tabB_stack.getChildren().add(new Label("Label@Tab B"));
        tabB.setContent(tabB_stack);
        tabPane.getTabs().add(tabB);

        Tab tabC = new Tab();
        tabC.setText("Last Component");
        //Add something in Tab
        StackPane tabC_vBox = new StackPane();
        tabC_vBox.setAlignment(Pos.CENTER);
        tabC_vBox.getChildren().add(new Label("Label@Tab C"));
        tabC.setContent(tabC_vBox);
        tabPane.getTabs().add(tabC);

        mainPane.setCenter(tabPane);

        mainPane.prefHeightProperty().bind(scene.heightProperty());
        mainPane.prefWidthProperty().bind(scene.widthProperty());

        root.getChildren().add(mainPane);
        primaryStage.setScene(scene);
        primaryStage.show();

How I can add horizontal and vertical scroll Pane into the tab's body. I want to display the scroll pane only when the data is bigger than the visible area. Is this possible?

1
0
6/8/2013 12:59:24 PM

Instead of setting contents of tabs to StackPane, call setContent method with ScrollPane object, and set the content of this ScrollPane to the corresponding StackPane.

2
6/11/2013 3:41:52 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon