如果您想要这种类型的流程,您可以通过隐藏选项卡来实现此目的,以便无法单击它们,然后添加按钮以遍历每个选项卡
您将需要下面的行来隐藏选项卡
tabPane.setStyle("-fx-tab-max-height: -2;");//You can still see tabs at -1 not sure why
注意如果你想隐藏标题空间(如下面我的应用程序所示)你需要通过 css 来做,你可以忽略上面的行
.tab-pane {
-fx-tab-max-height: 0 ;
}
.tab-pane .tab-header-area {
visibility: hidden ;
}
您还需要查看按钮是如何设置到下一个选项卡和上一个选项卡的,因为我不确定您的应用程序会是什么样子,我只是用按钮完成的,但您可以使用相同的操作来移动认为他的标签
Button buttonPlus = new Button("+");
buttonPlus.setOnAction(event -> {
int selectedIndex = tabPane.getSelectionModel().getSelectedIndex();
if(selectedIndex<tabPane.getTabs().size()-1)
tabPane.getSelectionModel().select(++selectedIndex);
});
Button buttonMinus = new Button("-");
buttonMinus.setOnAction(event -> {
int selectedIndex = tabPane.getSelectionModel().getSelectedIndex();
if(selectedIndex>0)
tabPane.getSelectionModel().select(--selectedIndex);
});
同样提醒您,您可以通过像 tabPane.getSelectionModel().select(index); 这样传递索引或像 tabPane.getSelectionModel().select(tab); 这样传递特定选项卡来更改选项卡
一旦这些被创建并添加到场景中,您就可以轻松地点击每个选项卡
查看我的申请,如果您有任何问题,请告诉我
public class Main extends Application {
@Override
public void start(Stage stage) {
TabPane tabPane = new TabPane();
tabPane.setStyle("-fx-tab-max-height: -2;");//You can still see tabs at -1
createNewTab(tabPane);
createNewTab(tabPane);
createNewTab(tabPane);
stage.setScene(new Scene(tabPane));
stage.show();
}
private void createNewTab(TabPane tabPane){
Tab tab = new Tab();
tab.setClosable(false);
addNodesToTab(tabPane, tab);
tabPane.getTabs().add(tab);
}
private void addNodesToTab(TabPane tabPane, Tab tab){
Button buttonPlus = new Button("+");
buttonPlus.setOnAction(event -> {
int selectedIndex = tabPane.getSelectionModel().getSelectedIndex();
if(selectedIndex<tabPane.getTabs().size()-1)
tabPane.getSelectionModel().select(++selectedIndex);
});
Button buttonMinus = new Button("-");
buttonMinus.setOnAction(event -> {
int selectedIndex = tabPane.getSelectionModel().getSelectedIndex();
if(selectedIndex>0)
tabPane.getSelectionModel().select(--selectedIndex);
});
tab.setContent(new VBox(new Label("Tab:"+tabPane.getTabs().size()),buttonPlus, buttonMinus));
}
}