0

I need to start my application with an open tab (selected), I have the code

 SingleSelectionModel<Tab> selectionModel = tabPane.getSelectionModel();
 selectionModel.select(tab); 

works but it hides the other tabs existing.

they also tried to use

    selectionModel.select(1); //select by index starting with 0
    selectionModel.clearSelection(); //clear your selection

any help is welcome

Perco
  • 160
  • 1
  • 18

1 Answers1

0

Try this on method initialize:

    @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 ) );
    }

And later you can do this with an menu item :

    @FXML
    private void clickMenuItemClients( final ActionEvent event )
    {
        if ( selectionModel.isSelected( 1 ) )
        {
            selectionModel.selectNext();
        }
    }
ncardez
  • 139
  • 2
  • 11