/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package clicker; import com.sun.glass.ui.Robot; import java.util.logging.Level; import java.util.logging.Logger; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Bounds; import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.stage.StageStyle; /** * * @author fx */ public class SceneCoords extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage stage1) throws Exception { Stage stage2 = new Stage(); stage2.initStyle(StageStyle.UNDECORATED); stage1.setScene(getScene("stage1")); stage2.setScene(getScene("stage2")); stage1.setY(100); stage2.setY(128); stage1.setX(300); stage2.setX(300); stage1.show(); stage2.show(); } private Scene getScene(String name) { final Button b = new Button(name); b.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { printCoords(b); final Bounds localToScreen = b.localToScreen(b.getLayoutBounds()); // Robot robot = com.sun.glass.ui.Application.GetApplication().createRobot(); // robot.mouseMove((int) Math.round(localToScreen.getMinX() + localToScreen.getWidth() / 2), // (int) Math.round(localToScreen.getMinY() + localToScreen.getHeight() / 2)); } }); new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(2000); } catch (InterruptedException ex) { Logger.getLogger(SceneCoords.class.getName()).log(Level.SEVERE, null, ex); } printCoords(b); } }).start(); b.setAlignment(Pos.CENTER); final VBox vBox = new VBox(b); vBox.setAlignment(Pos.CENTER); final Scene scene = new Scene(vBox); return scene; } private void printCoords(Node node) { final Bounds localToScreen = node.localToScreen(node.getLayoutBounds()); System.out.println(node); System.out.println(localToScreen); } }