Javafx drag and drop TabPane

≯℡__Kan透↙ 提交于 2019-12-21 20:04:50

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/15313796/javafx-drag-and-drop-tabpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!