3
votes

I have (in a JavaFx app) a tabpane with different tabs. I want to implement a drag and drop functionality to drag a tab outside the stage. So that it can generate a new window (like in Google Chrome).

Thanks for the help.

2
Welcome to Stackoverflow. Would you tell or show us how far you got? - Don Cruickshank
I'm also interested is there any implemented example. - Peter Penzov
Can you show us some sample code if you solved the problem? - Peter Penzov
What is your question? - Neuron

2 Answers

0
votes

You should check the solution by Tom Schindl shown at his Blog

-1
votes

Here is an aproach, its just the part of taking the content out into a new window, but its a start.

private Tab createTab(String text) {
        final Tab tab = new Tab();
        final Label label = new Label(text);
        tab.setGraphic(label);
        label.setOnDragDone(new EventHandler<DragEvent>() {

            @Override
            public void handle(DragEvent event) {
                if (event.getAcceptedTransferMode() == null) {
                    final StackPane content = (StackPane) tab.getContent();
                    tab.setContent(null);
                    Stage stage = new Stage();
                    stage.setScene(new Scene(content));
                    stage.show();
                    tab.getTabPane().getTabs().remove(tab);

                    event.consume();

                }

            }
        });
}

Basically you must create the tab with this method, and if the receiver of the event does not support draging, that is to say, if it does not do anything specific, then you create a new stackPane with the content of the tab.

*By the way is suposed the content of the pane was a StackPane.