我需要使用打开的标签(已选中)启动我的应用程序,我有代码
SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel();
selectionModel.select(tab);
有效,但它会隐藏现有的其他标签。
他们也试图使用
selectionModel.select(1); //select by index starting with 0
selectionModel.clearSelection(); //clear your selection
欢迎任何帮助
答案 0 :(得分:0)
尝试初始化方法:
@FXML
private TabPane tabPane;
private Tab clienTab = new Tab( "Clients" );
private Tab byMonthTab = new Tab( "By Months" );
private Tab aboutTab = new Tab( "About" );
@Override
public void initialize( final URL location, final ResourceBundle resources )
{
private ObservableList<Tab> observerList = null;
SingleSelectionModel<Tab> selectionModel = null;
if ( selectionModel == null )
{
selectionModel = tabPane.getSelectionModel();
}
if ( observerList == null )
{
observerList = FXCollections.observableArrayList();
}
observerList.add( clienTab );
observerList.add( monthsTab );
observerList.add( aboutTab );
tabPane.getTabs().setAll( observerList );
selectionModel.select( observerList.get( 1 ) );
}
稍后您可以使用菜单项执行此操作:
@FXML
private void clickMenuItemClients( final ActionEvent event )
{
if ( selectionModel.isSelected( 1 ) )
{
selectionModel.selectNext();
}
}