因此,我上次询问有关拖放的问题,并且由于有了帮助,我几乎掌握了它。我将矩形从左侧的Anchorpane拖到右侧窗格后,如果我尝试在第二个窗格中抓住矩形,它只会在显示InvocationTargetException之前移动几毫米。那就是我的代码:
DataFrame
谢谢!
编辑:对不起,我不知道我必须显示stacktrace
public void smthOver(DragEvent de) {
if (de.getGestureSource() == rect || de.getGestureSource() == ovalo || de.getGestureSource() == strich) {
de.acceptTransferModes(TransferMode.ANY);
de.consume();
} else {
de.acceptTransferModes();
}
public void smthDropped(DragEvent de) {
if (de.getGestureSource() == rect) {
dropZone.getChildren().add(rect);
de.consume();
} else if (de.getGestureSource() == ovalo) {
dropZone.getChildren().add(ovalo);
de.consume();
} else if (de.getGestureSource() == strich) {
dropZone.getChildren().add(strich);
de.consume();
}
}
public void smthDetectedRect(MouseEvent me) {
try {
Dragboard db = rect.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.putString(rect.getId());
db.setContent(content);
me.consume();
} catch (Exception e) {
e.printStackTrace();
}
}
public void smthPressedRect(MouseEvent me) {
x = me.getSceneX();
y = me.getSceneY();
orgTranslateX = ((Rectangle) (me.getSource())).getTranslateX();
orgTranslateY = ((Rectangle) (me.getSource())).getTranslateY();
rect.setCursor(Cursor.HAND);
}
public void smthDraggedRect(MouseEvent me) {
double offsetX = me.getSceneX() - x;
double offsetY = me.getSceneY() - y;
double newTranslateX = orgTranslateX + offsetX;
double newTranslateY = orgTranslateY + offsetY;
((Rectangle) (me.getSource())).setTranslateX(newTranslateX);
((Rectangle) (me.getSource())).setTranslateY(newTranslateY);
因此,我理解以下例外情况:我在“ smthDropped”中的窗格中添加了多个名称为“ rect”的子级,但是您知道如何解决此问题?因为我使用“ smthDropped”将形状从左侧窗格添加到右侧。希望这能解决困惑