'How can I use TabPane REORDER in FXML Controller

I have this problem I'm trying to use tabPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER); Inside AppSceneController.java

This code works very well but I want to try in FXML file ,

public class App extends Application {
    @Override
    public void start(Stage primaryStage) throws Exception {
        TabPane tabPane = new TabPane();
        tabPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER);
        Tab tab1 = new Tab("Tab1", new Label("Show all Tab1 available"));
        Tab tab2 = new Tab("Tab2", new Label("Show all Tab2 available"));
        tabPane.getTabs().add(tab1);
        tabPane.getTabs().add(tab2);
        Scene scene = new Scene(tabPane);
        primaryStage.setScene(scene);
        primaryStage.show();
    }
    public static void main(String[] args) {
        launch(args);
    }
}

My Example Code In : AppSceneController.java

public class AppSceneController {

    @FXML
    private TabPane mainTabPane;

    @FXML
    void initialize() { 
        mainTabPane.setTabDragPolicy(TabPane.TabDragPolicy.REORDER);
    }
}

My Example Code in My Main : App.java

public class App extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
       
        Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("App.fxml"));
        Scene scene = new Scene(root);

        primaryStage.setTitle("Hello, World!");
        primaryStage.setMaximized(true);
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

My FXML File Looks looks like, enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source