/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. * */ import javafx.application.Application; import javafx.embed.swing.SwingNode; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.input.MouseEvent; import javafx.scene.layout.BorderPane; import javafx.scene.layout.FlowPane; import javafx.stage.Stage; import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingUtilities; /** * Create tests for RT-31957. * Test checks that cursor changes corresponding to SwingNode content. * @author andrei-eremeev */ public class FXTest extends Application { private SwingNode swingNode; private Button pass; private Button fail; @Override public void start(Stage stage) throws Exception { stage.setTitle("CursorCorrespondsContentTest dialog"); final BorderPane pane = new BorderPane(); final FlowPane childPane = new FlowPane(); childPane.setAlignment(Pos.CENTER); childPane.setVgap(10); childPane.setHgap(10); childPane.setPadding(new Insets(10, 10, 10, 10)); pane.setPadding(new Insets(10, 10, 0, 10)); swingNode = new SwingNode(); init(swingNode); ButtonEventHandler handler = new ButtonEventHandler(); pass = new Button("Pass"); pass.setOnMouseClicked(handler); fail = new Button("Fail"); fail.setOnMouseClicked(handler); childPane.getChildren().addAll(pass, fail); pane.setCenter(swingNode); pane.setBottom(childPane); Scene scene = new Scene(pane, 500, 200); stage.setScene(scene); stage.show(); stage.centerOnScreen(); } private void init(final SwingNode swingNode) { SwingUtilities.invokeLater(new Runnable() { public void run() { try { JTextArea c = new JTextArea(); c.setText("Check that mouse cursor changes\nwhen it moves on text area"); swingNode.setContent(c); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }); } private class ButtonEventHandler implements EventHandler { @Override public void handle(MouseEvent t) { init(swingNode); } } public static void main(String[] args) { launch(args); } }