How can I get the mouse pointer inside a scroll pan in javafx? I have an app that does a drag and drop operation inside it, and I need that information to position the node on the screen.
The scroll pane is Pannable.
If you need to see some more of it, just ask, but I think I've posted what is necessary for the understanding to be clear already.
publicEventHandler<?superMouseEvent>getStartClassDrag(Noden,TipoClasset){return(e)->{//this.ac_comp.setDisable(true);ClipboardContentcc=newClipboardContent();cc.putUrl(FXMLFile.CLASSE);n.startDragAndDrop(TransferMode.ANY).setContent(cc);//Trechodecódigooriginal//sp_desktop.onDragDroppedProperty().set((evet)->{//Soluçãopn_desktop.onDragDroppedProperty().set((evet)->{if(evet.getDragboard().getUrl().equals(FXMLFile.CLASSE)){FXMLLoaderloader=newFXMLLoader(getClass().getResource(FXMLFile.CLASSE));try{loader.load();}catch(Exceptionerr){err.printStackTrace();}ClasseControllercontroller=loader.getController();controller.inicializar(this);controller.classe.setTipo(t);classes.add(controller);Point2Dteste=newPoint2D(evet.getX()+sp_desktop.getHvalue(),evet.getY()+sp_desktop.getVvalue());System.out.println(sp_desktop.getHvalue()+"x" + sp_desktop.getVvalue());
teste = sp_desktop.parentToLocal(teste);
relocateToPoint(teste.getX(), teste.getY(), controller.ap_classe);
controller.ap_classe.setVisible(true);
}
});
//Trecho de código original
//sp_desktop.onDragOverProperty().set((evento) -> {
//Solução
pn_desktop.onDragOverProperty().set((evento) -> {
if(evento.getDragboard().getUrl().equals(FXMLFile.CLASSE)) {
evento.acceptTransferModes(TransferMode.ANY);
}
evento.consume();
});
n.onDragDoneProperty().set((aux) ->{
sp_desktop.onDragDroppedProperty().set(null);
sp_desktop.onDragOverProperty().set(null);
ac_comp.setDisable(false);
});
};
}
protected void relocateToPoint(double x, double y, AnchorPane no) {
no.setVisible(true);
pn_desktop.getChildren().remove(no);
pn_desktop.getChildren().add(no);
no.setLayoutX(x - (no.getWidth() / 2));
no.setLayoutY(y - (no.getHeight() / 2));
}