JavaFX TabPane: How to set the selected tab

后端 未结 4 1817
一向
一向 2021-02-02 05:50

I have a Java Desktop Application with JavaFX 2 in it and in my FX I\'ve got a TabPane. I want to set the default tab. In other words I want to set a tab as selected. I found th

4条回答
  •  情话喂你
    2021-02-02 06:29

    To continue with Menai's answer heres how to refocus the opened tab/TabPane.

    SingleSelectionModel selectionModel = TabPane.getSelectionModel();
    if(!Tabpane.getTabs().contains(tabName)) {
       TabPane.getTabs().add(tabName);
       selectionModel.select(tabPane);
    } else {
       selectionModel.select(tabPane); 
    }
    

提交回复
热议问题