1
How do I get the mouse position inside a scroll pane 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 any more pieces of Có just ask, but I think I posted what needed understanding to be clear now.
public EventHandler<? super MouseEvent> getStartClassDrag(Node n, TipoClasse t) {
return (e) ->{
//this.ac_comp.setDisable(true);
ClipboardContent cc = new ClipboardContent();
cc.putUrl(FXMLFile.CLASSE);
n.startDragAndDrop(TransferMode.ANY).setContent(cc);
//Trecho de código original
//sp_desktop.onDragDroppedProperty().set((evet) -> {
//Solução
pn_desktop.onDragDroppedProperty().set((evet) -> {
if(evet.getDragboard().getUrl().equals(FXMLFile.CLASSE)) {
FXMLLoader loader = new FXMLLoader(getClass().getResource(FXMLFile.CLASSE));
try {
loader.load();
} catch (Exception err) { err.printStackTrace(); }
ClasseController controller = loader.getController();
controller.inicializar(this);
controller.classe.setTipo(t);
classes.add(controller);
Point2D teste = new Point2D(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));
}
Our language is the Português, translate your question.
– user28595