mouseevent - Dragging a window in Javafx -
i tried many other links still not getting success in dragging undecorated window in javafx.this code: >main
fxmlloader loader = new fxmlloader(getclass().getresource("videofxml.fxml")); stage.setscene(new scene( loader.load())); stage.initstyle(stagestyle.undecorated); videofxmlcontroller controller = loader.getcontroller(); controller.registerstage(stage); stage.show();
controller code:
public class videofxmlcontroller implements initializable { int = 0 , j = 0; @fxml private anchorpane basepane; @fxml private mediaview mediaview; @fxml private button btnext; @fxml public pane dragnode; public void registerstage(stage stage) { effectutilities.makedraggable(stage, dragnode); } public void btnexit(actionevent event){ if(event.getsource() == btnext){ system.exit(1); } } @override public void initialize(url url, resourcebundle rb) { try { playvideo(); } catch (malformedurlexception ex) { logger.getlogger(videofxmlcontroller.class.getname()).log(level.severe, null, ex); } }
}
effectutilities.java:
public static void makedraggable(stage stage, final pane bynode) { final delta dragdelta = new delta(); bynode.setonmousepressed((mouseevent mouseevent) -> { dragdelta.x = stage.getx() - mouseevent.getscreenx(); dragdelta.y = stage.gety() - mouseevent.getscreeny(); bynode.setcursor(cursor.move); }); bynode.setonmousereleased((mouseevent mouseevent) -> { bynode.setcursor(cursor.hand); }); bynode.setonmousedragged((mouseevent mouseevent) -> { stage.setx(mouseevent.getscreenx() + dragdelta.x); stage.sety(mouseevent.getscreeny() + dragdelta.y); }); } private static class delta { double x, y;
}
i refered following link:dragging undecorated stage in javafx still not getting doing wrong.i new javafx.please give me solution.thanks in advance
Comments
Post a Comment