JavaFx 设置TabPane指定选项卡选中

设置TabPane指定选项卡选中

JavaFx国内文档比较少,这是设置指定选项卡选中
下面是设置选项卡
------------------------------------------------>>>>>>>>>>>>>>>>
TabPane tabPane = new TabPane();

Tab tab0 = new Tab(“blue”);
tab.setContent(new Rectangle(200,200, Color.BLUE));

Tab tab1 = new Tab(“green”);
tab.setContent(new Rectangle(200,200, Color.GREEN));

tabPane.getTabs().addAll(tab0, tab1);
<<<<<<<<<<<<<<<<<<--------------------------------------

下面是设置指定选项卡选中
======>>>>>>>>>begin
SingleSelectionModel selectionModel = tabPane.getSelectionModel();
将其存储在某个局部变量中后,您可以使用不同的选项来选择选项卡。

selectionModel.select(tab1); //select by object
selectionModel.select(1); //select by index starting with 0
selectionModel.clearSelection(); //clear your selection
end<<<<<<<<<================

当然可以简化上面操作:
tabPane .getSelectionModel().select(tab1);

你可能感兴趣的:(JavaFx,JavaFx)