我有这个简单的 JavaFX 选项卡示例
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();
如何将水平和垂直滚动窗格添加到选项卡的正文中。我只想在数据大于可见区域时显示滚动窗格。这可能吗?