0

Inside of my JPanel, I have a button calling SimpleBrowser

    JButton swingButton = new JButton();
    swingButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            SimpleBrowser openBrowser = new SimpleBrowser();
            openBrowser.main((new String[0]));
        }
    });

    swingButton.setText("Browser");
    add(swingButton, BorderLayout.SOUTH);

this is my SimpleBrowser class

public class SimpleBrowser extends Application {

VBox vb = new VBox();

public void main(String[] args) {
    Application.launch(args);
}
@Override
public void start(Stage primaryStage) {
    vb.setId("root");

    WebView browser = new WebView();
    WebEngine engine = browser.getEngine();
    String url = "https://www.google.com";
    engine.load(url);

    vb.getChildren().addAll(browser);

    Scene scene = new Scene(vb);
    primaryStage.setScene(scene);
    primaryStage.show();
}

When I run this code, JButton opens up properly SimpleBrowser and display google. However, when I close this application and repress JButton, nothing happens. It suppose to relaunch SimpleBrowser and display google.

Could you guys help me?

Haroldy
  • 111
  • 2
  • 12
  • 1
    The way to go is switching scenes, or maybe having a StringPropertie with the page URL and change that, resulting in a reload. _(No time for an answer.)_ – Joop Eggen Nov 18 '14 at 15:47

1 Answers1

1

I actually find this code from oracle which helped me a lot.

I will share it here just in case if anyone needs

https://docs.oracle.com/javafx/2/swing/SimpleSwingBrowser.java.htm

explanation can be found here

https://docs.oracle.com/javafx/2/swing/swing-fx-interoperability.htm#CHDIEEJE

Thank you for trying to help me

Haroldy
  • 111
  • 2
  • 12