Javafx 如何检测拖板';舞台外的元素是什么?

Javafx 如何检测拖板';舞台外的元素是什么?,javafx,Javafx,我正在使用tabpane。我想使标签可拆卸。问题可能是拖板 我尝试在选项卡的图形上使用MouseRelease事件来检测其位置,但只有当我删除拖动事件时,它才起作用: graphic.setOnMouseReleased(e -> { Point2D mouseLoc = new Point2D(e.getScreenX(), e.getScreenY()); Window window = tabPane.getScene().getWin

我正在使用tabpane。我想使标签可拆卸。问题可能是拖板

我尝试在选项卡的图形上使用MouseRelease事件来检测其位置,但只有当我删除拖动事件时,它才起作用:

graphic.setOnMouseReleased(e -> {
            Point2D mouseLoc = new Point2D(e.getScreenX(), e.getScreenY());
            Window window = tabPane.getScene().getWindow();
            Rectangle2D windowBounds = new Rectangle2D(window.getX(), window.getY(), window.getWidth(), window.getHeight());
            if(!windowBounds.contains(mouseLoc)){
                System.out.println("new stage");
            }
        });
我的拖拽活动运行得很好。我使用此方法向选项卡添加处理程序:

public void addDragHandlers(Tab tab) {
        javafx.scene.control.Label label = new javafx.scene.control.Label(tab.getText(), tab.getGraphic());
        if (tab.getText() != null && !tab.getText().isEmpty()) {
            tab.setText(null);
            tab.setGraphic(label);
        }

        Node graphic = tab.getGraphic();
        graphic.setOnMouseReleased(e -> {
            Point2D mouseLoc = new Point2D(e.getScreenX(), e.getScreenY());
            Window window = tabPane.getScene().getWindow();
            Rectangle2D windowBounds = new Rectangle2D(window.getX(), window.getY(), window.getWidth(), window.getHeight());
            if(!windowBounds.contains(mouseLoc)){
                System.out.println("new stage");
            }
        });

        graphic.setOnDragDetected(e -> {
            Dragboard dragboard = graphic.startDragAndDrop(TransferMode.MOVE);
            ClipboardContent content = new ClipboardContent();
            content.putString(draggingID);
            dragboard.setContent(content);
            dragboard.setDragView(graphic.snapshot(null, null));
            currentDraggingTab = tab;
        });

        graphic.setOnDragOver(e -> {
            if (draggingID.equals(e.getDragboard().getString()) &&
                    currentDraggingTab != null &&
                    currentDraggingTab.getGraphic() != graphic) {
                e.acceptTransferModes(TransferMode.MOVE);
            }
        });

        graphic.setOnDragDropped(e -> {
            if (draggingID.equals(e.getDragboard().getString()) &&
                    currentDraggingTab != null &&
                    currentDraggingTab.getGraphic() != graphic) {
                int index = tab.getTabPane().getTabs().indexOf(tab);
                currentDraggingTab.getTabPane().getTabs().remove(currentDraggingTab);
                tab.getTabPane().getTabs().add(index, currentDraggingTab);
                currentDraggingTab.getTabPane().getSelectionModel().select(currentDraggingTab);
            }
        });

        graphic.setOnDragDone(e -> currentDraggingTab = null);
    }
如何在拖动处理程序中实现分离功能


谢谢你的帮助,很抱歉我的英语不好

你看过这个教程了吗@本教程使用鼠标事件。DrageEvent阻止鼠标事件是有原因的。但是,正如我写的鼠标事件的作品,但我需要的位置变化拖动事件你看了这个教程吗@本教程使用鼠标事件。DrageEvent阻止鼠标事件是有原因的。但正如我用鼠标事件写的一样,我需要拖动事件来改变位置