import com.sun.glass.ui.Robot; import java.awt.event.MouseEvent; import javafx.application.Application; import javafx.embed.swing.SwingNode; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javafx.stage.WindowEvent; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author andrei-eremeev */ public abstract class SwingNodeBaseTest extends Application { public static void main(String[] args) { launch(args); } protected abstract void init(final SwingNode node) throws Exception; protected abstract void doTest(Stage stage) throws Exception; protected abstract boolean check(); @Override public void start(final Stage stage) throws Exception { SwingNode swingNode = new SwingNode(); init(swingNode); StackPane pane = new StackPane(); pane.getChildren().add(swingNode); Scene scene = new Scene(pane, 300, 300); stage.setScene(scene); stage.setX(75); stage.setY(75); stage.setOnShown(new EventHandler() { @Override public void handle(WindowEvent t) { try { Thread thread = new Thread(new Runnable() { @Override public void run() { try { // Remove this method after fix in jfx! resize(stage); doTest(stage); if (check()) { //System.exit(0); } else { //System.exit(1); } } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }); thread.start(); } catch (Exception ex) { ex.printStackTrace(); System.exit(1); } } }); stage.show(); } // Remove this method after fix in jfx! private void resize(Stage stage) { Robot robot = createRobot(); int x = (int) (stage.getX()); int y = (int) (stage.getY() + stage.getHeight()); robot.mouseMove(x + 5, y - 5); robot.mousePress(MouseEvent.BUTTON1); delay(50); robot.mouseMove(x - 5, y); robot.mouseRelease(MouseEvent.BUTTON1); delay(50); } public Robot createRobot() { return com.sun.glass.ui.Application.GetApplication().createRobot(); } public void delay(int delay) { try { Thread.sleep(delay); } catch (Exception e) { } } }