請嘗試對方法初始化:
@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();
}
}