我在位于 JPanel 上的 JFXPanel 上的拖放事件有问题。当我将拖动消息推送到 DragBoard 时,应用程序的 javaFX 部分不再工作。我认为它与摇摆事件机制有关,但我不确定。其他事件没有问题。这让我很困惑。这个问题有什么解决办法吗?提前致谢。
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);
}
}