How to set tabs position in JavaFX


Question

I have this JavaFX code with tabs. Can you tell me how I can set the position of the tabs panel to be always on the left side of the main stage:

VBox stackedTitledPanes = createStackedTitledPanes();

        ScrollPane scroll = makeScrollable(stackedTitledPanes);

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

        tabPane.setStyle("-fx-font-size: 12pt;"); // Set global size for the font
        // Create Tabs
        Tab tabA = new Tab();
        tabA.setText("Main Component");
        tabA.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name
        // Add something in Tab
        StackPane tabA_stack = new StackPane();
        tabA_stack.setAlignment(Pos.CENTER);
        tabA_stack.getChildren().add(scroll); 
        tabA.setContent(tabA_stack);
        tabPane.getTabs().add(tabA);

        Tab tabB = new Tab();
        tabB.setText("Second Component");
        tabB.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name
        // 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");
        tabC.setStyle("-fx-font-size: 12pt;"); // Set size of the tab name
        // 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.setPrefSize(395, 580);
        mainPane.setLayoutX(850);
        mainPane.setLayoutY(32);

        scroll.setPrefSize(395, 580);
        scroll.setLayoutX(850);
        scroll.setLayoutY(32);

        root.getChildren().add(mainPane);
1
1
6/4/2013 6:02:51 PM

Accepted Answer

Update

Sounds like you want to change your stackedTitledPane from a VBox to a BorderPane. So this code:

VBox stackedTitledPanes = new VBox();

becomes:

BorderPane stackedTitledPanes = new BorderPane();

Then when you want to add your nodes, you specify which section you want to put them (I put a label in the center pane as a filler):

stackedTitledPanes.setLeft(mainPane);
stackedTitledPanes.setCenter(new Label("Main Content"));

Old answer

This will put the tabs on the left (I'm assuming this is what you're looking for):

    tabPane.setSide(Side.LEFT);

TabPane Left side

3
6/4/2013 7:10:49 PM

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