How to remove close button from tabs in JavaFX

You can set the TabClosingPolicy on a TabPane

myTabPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);

There are the following possibilities:

  • TabClosingPolicy.ALL_TABS // all tabs can be closed
  • TabClosingPolicy.SELECTED_TAB // only the selected tab can be closed
  • TabClosingPolicy.UNAVAILABLE // you cant close

If you are adding classes to myTabPane.getTabs() there is also the possibility to set the class to not be closeable (because it needs to extend from Tab):

setClosable(false);

If you define it in the class which extends from Tab I guess the policy you set will be useless and is overridden.

Link to the oracle doc: JavaFX 8 TabPane.TabClosingPolicy


You can also define this using FXML by this code:

<TabPane tabClosingPolicy="UNAVAILABLE">

Tags:

Java

Javafx