1

我有这个带有标签的 JavaFX 代码。您能告诉我如何将选项卡面板的位置设置为始终位于主舞台的左侧:

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);
4

1 回答 1

3

更新

听起来您想将您的stackedTitledPane从 a更改VBox为 a BorderPane。所以这段代码:

VBox stackedTitledPanes = new VBox();

变成:

BorderPane stackedTitledPanes = new BorderPane();

然后,当您要添加节点时,指定要放置它们的部分(我在中心窗格中放置了一个标签作为填充物):

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

旧答案

这会将选项卡放在左侧(我假设这是您要查找的内容):

    tabPane.setSide(Side.LEFT);

TabPane 左侧

于 2013-06-04T18:48:55.407 回答