<AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
<children>
<TabPane fx:id="tabPane">
<tabs>
<Tab text="Tab 1"/>
<Tab text="Tab 2"/>
</tabs>
</TabPane>
</children>
</AnchorPane>
在控制器中注入TabPane并通过代码设置选中状态,下面的代码是默认选中第二个
package sample;
import javafx.fxml.Initializable;
import javafx.scene.control.TabPane;
import java.net.URL;
import java.util.ResourceBundle;
public class Controller implements Initializable {
@FXML
private TabPane tabPane;
@Override
public void initialize(URL location, ResourceBundle resources) {
tabPane.getSelectionModel().select(1);
}
}