本文介绍了从javaFX场景拖放到Windows资源管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从javaFX场景拖放到Windows资源管理器?

解决方案

是的,有
您应该使用onDragDetected函数来启动dragEvent和onDragDone函数,以便在完成拖动操作后执行任何操作。这是一个例子:

  final text source = new文字(50,100,DRAG ME); 

source.setOnDragDetected(new EventHandler< MouseEvent>(){
public void handle(MouseEvent event){
/ *检测到拖动,开始拖放手势* /
System.out.println(onDragDetected);

/ *允许任何传输模式* /
Dragboard db = source.startDragAndDrop(TransferMode.ANY);

/ *在dragboard上放置一个字符串* /
ClipboardContent content = new ClipboardContent();
content.putString(source.getText());
db.setContent (内容);

event.consume();
}


source.setOnDragDone(new EventHandler< DragEvent>(){
public void handle(DragEvent事件){
/ *拖放手势结束* /
System.out.println(onDragDone);
/ *如果数据已成功移动,清除它* /
if(event.getTransferMod e()== TransferMode.MOVE){
source.setText();
}

event.consume();
}
});


Is there any way to Drag and drop from javaFX scene to windows explorer?

解决方案

Yes there isYou should use the onDragDetected function to start your dragEvent and the onDragDone function for doing whatever you want after finishing the drag & drop.

Here an example:

final Text source = new Text(50, 100, "DRAG ME");

    source.setOnDragDetected(new EventHandler <MouseEvent>() {
        public void handle(MouseEvent event) {
            /* drag was detected, start drag-and-drop gesture*/
            System.out.println("onDragDetected");

            /* allow any transfer mode */
            Dragboard db = source.startDragAndDrop(TransferMode.ANY);

            /* put a string on dragboard */
            ClipboardContent content = new ClipboardContent();
            content.putString(source.getText());
            db.setContent(content);

            event.consume();
        }


source.setOnDragDone(new EventHandler <DragEvent>() {
        public void handle(DragEvent event) {
            /* the drag-and-drop gesture ended */
            System.out.println("onDragDone");
            /* if the data was successfully moved, clear it */
            if (event.getTransferMode() == TransferMode.MOVE) {
                source.setText("");
            }

            event.consume();
        }
    });

这篇关于从javaFX场景拖放到Windows资源管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 20:05