2012-04-26 74 views
1

我在JFXPanel上的位于JPanel上的拖放事件有问题。当我将拖动消息推送到DragBoard时,应用程序的javaFX部分不再起作用。我认为它关于摆动事件mechanizm,但我不确定。其他事件没有问题。这让我感到困惑。有没有解决这个问题的方法?提前致谢。如何使用Swing在JavaFX 2.2中进行拖放操作?

public class MyScene extends Scene { 

    public MyScene(VBox vBoxMainLayout) { 
     super(vBoxMainLayout); 

     HBox hBox = new HBox(); 
     hBox.setPrefSize(10000, 10000); 
     hBox.setSpacing(40); 

     Button buttonSource = new Button("Source"); 
     buttonSource.setMinSize(60, 30); 

     buttonSource.setOnDragDetected(new EventHandler<MouseEvent>() { 
      public void handle(MouseEvent event) { 
       Dragboard db = startDragAndDrop(TransferMode.ANY); 

       ClipboardContent content = new ClipboardContent(); 
       String message = "Drag operatation is done"; 
       content.putString(message); 
       db.setContent(content); 
       event.consume(); 
      } 
     }); 

     buttonSource.setOnDragDone(new EventHandler<DragEvent>() { 
      public void handle(DragEvent event) { 

       event.consume(); 
      } 
     }); 

     TextArea textAreaTarget = new TextArea(); 
     textAreaTarget.setMinSize(200, 500); 

     hBox.getChildren().add(buttonSource); 
     hBox.getChildren().add(textAreaTarget); 

     vBoxMainLayout.getChildren().add(hBox); 
    } 

} 

public class Main extends Application { 

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

    @Override 
    public void start(Stage stage) { 
     VBox vBoxMainLayout = new VBox(); 
     MyScene myScene = new MyScene(vBoxMainLayout); 

     JFrame frame = new JFrame(); 
     JFXPanel arg0 = new JFXPanel(); 
     arg0.setScene(myScene); 
     frame.getContentPane().add(arg0); 
     frame.setVisible(true); 

    } 
} 
+0

谢谢。它看起来像一个错误。你怎么看待这件事? – 2012-04-27 08:01:25

回答

0

这是JavaFX 2.1中已知的死锁,并推到2.2(这是我从oracle学到的),但我想它仍然没有解决。