我有一个JavaFX项目,我有一个锚板,我有自己的组件:classBox(扩展一个vBox)使这个Box可移动我使用下面的代码。 我遇到的问题是,有时当我运行我的项目并开始移动框时,我的porgram停止响应,然后当我关闭它时,我得到退出代码-805306369。 我不知道为什么我得到这个错误,为什么只有somtimes而不是总是。 (我使用intellij来运行我的程序)
public class BoxView extends ClassBox implements InvalidationListener {
private BoxModel model;
public BoxView(BoxModel model) {
this.model = model;
model.addListener(this);
makeDragable();
heightProperty().addListener((Observable o) -> model.setHeight(getHeight()));
}
@Override
public void invalidated(Observable observable) {
if (model.getBox() != null){
setName(model.getBox().getName());
setAttributes(model.getBox().getAttributes());
setOperations(model.getBox().getOperations());
setPrefWidth(model.getBox().getWidth());
setLayoutX(model.getBox().getCol());
setLayoutY(model.getBox().getRow());
}
}
public void makeDragable(){
final Coordinate cornerDist = new Coordinate();
this.setOnMouseEntered(mouseEvent -> this.setCursor(Cursor.HAND));
this.setOnMouseReleased(mouseEvent -> this.setCursor(Cursor.HAND));
this.setOnMousePressed(mouseEvent -> {
this.setCursor(Cursor.MOVE);
cornerDist.setX(this.getLayoutX() - mouseEvent.getSceneX());
cornerDist.setY(this.getLayoutY() - mouseEvent.getSceneY());
});
this.setOnMouseDragged(mouseEvent -> model.setPos(new Coordinate(mouseEvent.getSceneX() + cornerDist.getX(),
mouseEvent.getSceneY() + cornerDist.getY())));
}
}