我想使用(JavaFX)TabPane显示20个不同选项卡的内容。这与标准TabPane一起工作良好,但是,当窗格触及一定数量的选项卡时,可以单击按钮/组合框以单击其中一个未显示的选项卡。带有多行选项卡的Javafx TabPane
我正在设计一个功能,将用于触摸屏,所以这是不理想的。我认为有两个单独的选项卡会更直观。
如何将两行选项卡添加到TabPane中,或者,可以做些什么来实现类似的效果?先谢谢了。
下面是一些示例代码重现我的意思:
public class TabTest extends Application {
public static void main(String args[]) {
Application.launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Tabs Test");
Group root = new Group();
Scene scene = new Scene(root, 450, 250, Color.WHITE);
TabPane tabPane = new TabPane();
BorderPane borderPane = new BorderPane();
for(int i = 0; i < 20; i++)
{
Tab tab = new Tab();
tab.setText("Tab " + i);
HBox hbox = new HBox();
hbox.getChildren().add(new Label("Tab " + i));
tab.setContent(hbox);
tabPane.getTabs().add(tab);
}
borderPane.prefHeightProperty().bind(scene.heightProperty());
borderPane.prefWidthProperty().bind(scene.widthProperty());
borderPane.setCenter(tabPane);
root.getChildren().add(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
}
Link to tabbed view, since I can't post images yet
您应该发布您尝试过的代码,但目前无法运行。 – ManoDestra
@ManoDestra谢谢,我用示例代码和图像链接更新了我的问题。 – Kornephoros