java - Moving undecorated stage Javafx with JXML and Scene Builder -
i'm trying capture x , y coordinates of undecorated pane in javafx. project created using javafx, jxml , scene builder. there other links on hints answer, i'm quite not able implement it. either build error exception or nan coordinates. minimum modifications required implement movable panes functionality following code?
here code mainapp.java (skipping imports handled netbeans well)
public class mainapp extends application { @override public void start(stage stage) throws exception { gridpane mainpane = fxmlloader.load(getclass().getresource("/fxml/scene.fxml")); scene scene = new scene(mainpane, color.transparent); scene.getstylesheets().add("/styles/styles.css"); stage.initstyle(stagestyle.transparent); stage.setscene(scene); stage.show(); } public static void main(string[] args) { launch(args); } }
fxmlcontroller.java
public class fxmlcontroller extends gridpane { public void rootnodeclick(mouseevent mouseevent) { system.out.println("click"); } public void rootnodedrag(mouseevent mouseevent) { system.out.println("drag"); } }
fxml
<?xml version="1.0" encoding="utf-8"?> <gridpane fx:id="mainpane" alignment="center" focustraversable="true" maxheight="550.0" maxwidth="600.0" minheight="550.0" minwidth="600.0" nodeorientation="left_to_right" onmouseclicked="#rootnodeclick" onmousedragged="#rootnodedrag" prefheight="550.0" prefwidth="600.0" style="-fx-background-color: #ecf0f1; -fx-background-radius: 3;" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="fxmlcontroller"> <columnconstraints> <columnconstraints hgrow="sometimes" minwidth="10.0" prefwidth="100.0" /> <columnconstraints hgrow="sometimes" minwidth="10.0" prefwidth="100.0" /> </columnconstraints> <rowconstraints> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> <rowconstraints minheight="10.0" prefheight="30.0" vgrow="sometimes" /> </rowconstraints> <effect> <innershadow blurtype="gaussian" color="#ffffff44" height="10.0" radius="4.5" width="10.0" /> </effect> </gridpane>
something should trick. when mouse pressed, capture x , y , set difference when drag over.
final delta dragdelta = new delta(); mainpane.setonmousepressed(new eventhandler<mouseevent>() { @override public void handle(mouseevent me) { if (me.getbutton() == mousebutton.primary) { dragdelta.x = me.getscenex(); dragdelta.y = me.getsceney(); } } }); mainpane.setonmousedragged(new eventhandler<mouseevent>() { @override public void handle(mouseevent me) { if (me.getbutton() == mousebutton.primary) { scene.getwindow().setx(me.getscreenx() - dragdelta.x); scene.sety(me.getscreeny() - dragdelta.y); } } });
here delta
public class delta { public double x; public double y; }
the original answer found on stackoverflow, used long time ago, can't find again, sorry original answer
Comments
Post a Comment