Search in sources :

Example 46 with JFXPanel

use of javafx.embed.swing.JFXPanel in project dwoss by gg-net.

the class PersonaManagmentControllerTest method testJavaFxFxml.

@Test
public void testJavaFxFxml() throws IOException {
    if (GraphicsEnvironment.isHeadless())
        return;
    // Implizit start of JavaFx.
    new JFXPanel();
    FXMLLoader loader = new FXMLLoader(PersonaManagmentController.loadFxml());
    loader.load();
    assertThat((PersonaManagmentController) loader.getController()).isNotNull();
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) FXMLLoader(javafx.fxml.FXMLLoader) Test(org.junit.Test)

Example 47 with JFXPanel

use of javafx.embed.swing.JFXPanel in project TrayNotification by PlusHaze.

the class ReadMeTest method initializeJavaFX.

@BeforeClass
public static void initializeJavaFX() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    SwingUtilities.invokeLater(() -> {
        // initializes JavaFX environment
        new JFXPanel();
        latch.countDown();
    });
    latch.await();
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 48 with JFXPanel

use of javafx.embed.swing.JFXPanel in project PokeGOAPI-Java by Grover-c13.

the class SolveCaptchaExample method completeCaptcha.

private static void completeCaptcha(final PokemonGo api, final String challengeURL) {
    // Run this on the swing thread
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            // Run on JFX Thread
            Platform.runLater(new Runnable() {

                @Override
                public void run() {
                    JFXPanel panel = new JFXPanel();
                    // Create a WebView and WebEngine to display the captcha from challengeURL.
                    WebView view = new WebView();
                    WebEngine engine = view.getEngine();
                    // Set UserAgent so the captcha shows correctly in the WebView.
                    engine.setUserAgent(CaptchaSolveHelper.USER_AGENT);
                    engine.load(challengeURL);
                    final JFrame frame = new JFrame("Solve Captcha");
                    // Register listener to receive the token when the captcha has been solved from inside the WebView.
                    CaptchaSolveHelper.Listener listener = new CaptchaSolveHelper.Listener() {

                        @Override
                        public void onTokenReceived(String token) {
                            System.out.println("Token received: " + token + "!");
                            // Remove this listener as we no longer need to listen for tokens, the captcha has been solved.
                            CaptchaSolveHelper.removeListener(this);
                            try {
                                // Close this window, it not valid anymore.
                                frame.setVisible(false);
                                frame.dispose();
                                if (api.verifyChallenge(token)) {
                                    System.out.println("Captcha was correctly solved!");
                                } else {
                                    // verifyChallenge will receive a new captcha url if this one is invalid
                                    System.out.println("Captcha was incorrectly solved! Please try again.");
                                }
                            } catch (Exception e) {
                                Log.e("Main", "Error while solving captcha!", e);
                            }
                        }
                    };
                    CaptchaSolveHelper.registerListener(listener);
                    // Applies the WebView to this panel
                    panel.setScene(new Scene(view));
                    frame.getContentPane().add(panel);
                    frame.setSize(500, 500);
                    frame.setVisible(true);
                    // Don't allow this window to be closed
                    frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
                    frame.addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosing(WindowEvent e) {
                            System.out.println("Please solve the captcha before closing the window!");
                        }
                    });
                }
            });
        }
    });
}
Also used : CaptchaSolveHelper(com.pokegoapi.util.CaptchaSolveHelper) JFXPanel(javafx.embed.swing.JFXPanel) LoginListener(com.pokegoapi.api.listener.LoginListener) WindowAdapter(java.awt.event.WindowAdapter) Scene(javafx.scene.Scene) WebEngine(javafx.scene.web.WebEngine) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WebView(javafx.scene.web.WebView)

Example 49 with JFXPanel

use of javafx.embed.swing.JFXPanel in project BlocklyArduinoIDEPlugin by technologiescollege.

the class LedMatrixPlugin method initGUI.

private void initGUI() {
    window = new JFrame();
    window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    window.setLayout(new BorderLayout());
    window.setSize(1024, 768);
    window.setLocationRelativeTo(null);
    window.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            SwingUtilities.invokeLater(() -> {
                Platform.runLater(() -> {
                    // browser.webEngine.load("about:blank");
                    SwingUtilities.invokeLater(() -> {
                        // System.out.println("test");
                        try {
                            e.getWindow().dispose();
                        } catch (NullPointerException ex) {
                        // System.out.println("This is a bug in java: https://bugs.openjdk.java.net/browse/JDK-8089371");
                        }
                    });
                });
            });
        }
    });
    jfxPanel = new JFXPanel();
    jfxPanel.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT));
    window.add(jfxPanel, BorderLayout.CENTER);
    window.setVisible(true);
    Platform.runLater(() -> {
        showBrowser();
    });
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) BorderLayout(java.awt.BorderLayout) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension)

Example 50 with JFXPanel

use of javafx.embed.swing.JFXPanel in project BlocklyArduinoIDEPlugin by technologiescollege.

the class StartupApplet method init.

@Override
public void init() {
    LedMatrixPlugin.startTimestamp = System.currentTimeMillis();
    fxContainer = new JFXPanel();
    fxContainer.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT));
    add(fxContainer, BorderLayout.CENTER);
    Platform.setImplicitExit(false);
    Runnable activeRunnable = new Runnable() {

        @Override
        public void run() {
            createScene();
        }
    };
    Platform.runLater(activeRunnable);
}
Also used : JFXPanel(javafx.embed.swing.JFXPanel) Dimension(java.awt.Dimension)

Aggregations

JFXPanel (javafx.embed.swing.JFXPanel)52 Scene (javafx.scene.Scene)16 Test (org.junit.Test)16 CountDownLatch (java.util.concurrent.CountDownLatch)11 Dimension (java.awt.Dimension)6 BorderPane (javafx.scene.layout.BorderPane)6 Stage (javafx.stage.Stage)6 FXMLLoader (javafx.fxml.FXMLLoader)5 WebView (javafx.scene.web.WebView)5 BorderLayout (java.awt.BorderLayout)4 WindowAdapter (java.awt.event.WindowAdapter)4 WindowEvent (java.awt.event.WindowEvent)4 ExecutorService (java.util.concurrent.ExecutorService)4 JFrame (javax.swing.JFrame)4 IOException (java.io.IOException)3 WebEngine (javafx.scene.web.WebEngine)3 PropertyChangeEvent (java.beans.PropertyChangeEvent)2 Random (java.util.Random)2 FutureTask (java.util.concurrent.FutureTask)2 Memory (php.runtime.Memory)2