JavaFX将节点/对象拖到Windows桌面

时间:2018-08-09 05:13:07

标签: windows macos javafx drag-and-drop

我在应用程序中使用JavaFX的Drag&Drop,它在MacOS-X上运行良好,但在Windows上却运行不佳。

目标是:将TabGraphic拖动到OS桌面时,我想创建一个新的 放置Tab位置的Window(场景)。在OS-X上,onMouseReleased被调用,但在Windows上不被调用。谁能告诉我,这是什么问题?我正在使用JDK 10.0.2

public class DragAndDropTest extends Application {

    @Override
    public void start(Stage primaryStage) {

        Tab tab = new Tab();
        tab.setGraphic(new Label("Drag me"));

        tab.getGraphic().setOnDragDetected(e -> {
            System.out.println("Drag detected");
            SnapshotParameters param = new SnapshotParameters();
            param.setTransform(Transform.scale(2, 2));
            WritableImage image = tab.getGraphic().snapshot(param, null);
            Dragboard dragboard = tab.getGraphic().startDragAndDrop(TransferMode.MOVE);
            dragboard.setDragView(image);
            ClipboardContent clipboardContent = new ClipboardContent();
            clipboardContent.putString("");
            dragboard.setContent(clipboardContent);
        });

        tab.getGraphic().setOnMouseReleased(e -> {
            System.out.println("Mouse Released");
        });

        TabPane tabpane = new TabPane();
        tabpane.getTabs().add(tab);

        StackPane stackpane = new StackPane();
        stackpane.getChildren().add(tabpane);

        Scene scene = new Scene(stackpane, 500, 250);
        primaryStage.setTitle("Drag to OS Test");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

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

}

0 个答案:

没有答案