2

I want to make all buttons work perfectly in a JavaFX application showing a web page inside a frame. All the application does is load and show the webpage that the URL is first set to. Doing things like searching google works perfectly. However, the web browser buttons don't always work. For example, if I try and sign into a google account, the "Next" button does not work, and this applies to all Google Drive services. How can I fix this? I am running my code on MacOS Mojave.

import javafx.application.Platform;
import javafx.embed.swing.JFXPanel;
import javafx.scene.Scene;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javax.swing.*;

public class LoadWebPage
{

public static void main(String args[])
{
    final JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.setSize(620, 440);
    final JFXPanel fxpanel = new JFXPanel();
    frame.add(fxpanel);

    Platform.runLater(new Runnable()
    {
        @Override
        public void run()
        {
            WebEngine engine;
            WebView wv = new WebView();
            engine = wv.getEngine();
            fxpanel.setScene(new Scene(wv));
            engine.load("https://www.google.com/");
        }
    });
    frame.setVisible(true);
}
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 2
    Why is the code embedding a `WebView` into a Swing based `JFrame`? There are good reasons for using one GUI toolkit or another, rather than both combined. BTW plus one for adding a [mcve]. – Andrew Thompson May 08 '19 at 08:02
  • 2
    *"I am running my code on MacOS Mojave."* I'm running the code on Windows 10 and get the same result. – Andrew Thompson May 08 '19 at 08:10
  • @AndrewThompson I used a JFrame simply because I am new to JavaFX and am in the process of transitioning from Swing. Do you know of any differences this could make with this code? That is, would using a more appropriate frame change the outcome? – Rohith Vishwajith May 09 '19 at 04:55
  • *"Do you know of any differences this could make with this code?"* Well, A Swing based `JFrame` should be started on the EDT, but doing that in combination with the FX thread is likely more complicated than doing it all in FX from the get go. *"That is, would using a more appropriate frame change the outcome?"* Nothing beats a test using code. – Andrew Thompson May 09 '19 at 07:47
  • How did it go with pure Java-FX? – Andrew Thompson May 11 '19 at 06:37
  • @AndrewThompson I did everything with JavaFX but had the same issues. Other than general conventions, I couldn't see any difference between using swing and a JavaFX hybrid when compared to just JavaFX. – Rohith Vishwajith May 11 '19 at 21:02
  • I think it's time to visit the [Java Bug Database](https://bugs.java.com/bugdatabase/) to check if an existing bug is listed, and if not, raise a report. – Andrew Thompson May 12 '19 at 04:34

0 Answers0