java - setOnMouseDragged not working on browser view -
i'm writing simple application in java using jxbrowser engine i'm stuck @ beginning. in code, there undecorated stage
want make draggable. so, searched , found following link:
so set mousepressed
, mousedragged
event on stackpane
mousepressed
event gets fired , mousedragged
event no way gets fired. idea of what's problem?
thanks in advance.
import com.teamdev.jxbrowser.chromium.browser; import com.teamdev.jxbrowser.chromium.javafx.browserview; import javafx.application.application; import javafx.application.platform; import javafx.event.eventhandler; import javafx.scene.scene; import javafx.scene.input.mouseevent; import javafx.scene.layout.stackpane; import javafx.stage.stage; import javafx.stage.stagestyle; private static double xoffset = 0; private static double yoffset = 0; public class main extends application { public static void main(string[] args) { launch(args); } @override public void start(stage primarystage) { platform.setimplicitexit(false); browser browser = new browser(); browserview browserview = new browserview(browser); stackpane pane = new stackpane(); pane.getchildren().add(browserview); scene scene = new scene(pane, 380, 500); primarystage.initstyle(stagestyle.undecorated); primarystage.setscene(scene); pane.setonmousepressed(new eventhandler<mouseevent>() { @override public void handle(mouseevent event) { system.out.println("mouse pressed"); xoffset = primarystage.getx() - event.getscreenx(); yoffset = primarystage.gety() - event.getscreeny(); } }); pane.setonmousedragged(new eventhandler<mouseevent>() { @override public void handle(mouseevent event) { system.out.println("mouse dragged"); primarystage.setx(event.getscreenx() + xoffset); primarystage.sety(event.getscreeny() + yoffset); } }); primarystage.show(); } }
since jxbrowser requires license couldn't test it... replaced label , works fine.. guess trying drag clicking on browser , not stackpane.. try clicking @ corner of stage or else add stack pane vbox , setpadding it.. , try clicking @ corner.. if clicking on browser browser's mouse events trigerred..
the correct code
package rezrem; import com.teamdev.jxbrowser.chromium.browser; import com.teamdev.jxbrowser.chromium.javafx.browserview; import javafx.application.application; import javafx.application.platform; import javafx.event.eventhandler; import javafx.geometry.insets; import javafx.scene.scene; import javafx.scene.input.mouseevent; import javafx.scene.layout.stackpane; import javafx.scene.layout.vbox; import javafx.stage.stage; import javafx.stage.stagestyle; public class main extends application { private static double xoffset = 0; private static double yoffset = 0; public static void main(string[] args) { launch(args); } @override public void start(stage primarystage) { platform.setimplicitexit(false); browser browser = new browser(); browserview browserview = new browserview(browser); stackpane pane = new stackpane(); pane.getchildren().add(browserview); pane.setpadding(new insets(10,10,10,10)); scene scene = new scene(pane, 380, 500); primarystage.initstyle(stagestyle.undecorated); primarystage.setscene(scene); pane.setonmousepressed(new eventhandler<mouseevent>() { @override public void handle(mouseevent event) { system.out.println("mouse pressed"); xoffset = primarystage.getx() - event.getscreenx(); yoffset = primarystage.gety() - event.getscreeny(); } }); pane.setonmousedragged(new eventhandler<mouseevent>() { @override public void handle(mouseevent event) { system.out.println("mouse dragged"); primarystage.setx(event.getscreenx() + xoffset); primarystage.sety(event.getscreeny() + yoffset); } }); browser.loadurl("http://www.google.com"); primarystage.show(); } }
reason
the jxbrowser extends till edge stack pane wasn't on top neither visible on sides mouse listener's never got triggered setting padding of stack pane there 10px gap on 4 sides where, if clicked, triggered mouse events , thereby solves problem..
Comments
Post a Comment