2013-03-19 47 views
0

我需要用一個打開的選項卡(選擇)開始我的申請,我的代碼SingleSelectionModel <Tab> - 隱藏其他選項卡

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

的作品,但它隱藏的其他選項卡存在。

他們還試圖用

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

任何幫助是值得歡迎

回答

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