JavaFX Webview

+1 Rutger Benoot · April 11, 2015
I was wondering if anyone knows how I can pass an object to a JavaFX WebView. To give some more info on what should happen:
I'm creating an application with an object that contains a list of months and a month contains it average temperature and total amount of downfall:

public class Klimatogram implements Serializable {
   private List maanden;
}


public class Maand implements Serializable {

    private double temperatuur;
    private int neerslag;

}

there are ofcourse getters for these values.

In my JavaFX application, I have created the following to render an html-page:
public class Browser extends Region{
        private final WebView webView = new WebView();
        private final WebEngine webEngine = webView.getEngine();
        
        public Browser(){
            getStyleClass().add("browser");
            webEngine.load("http://www.google.be");
            getChildren().add(webView);
        }
    }

With this I can show an html page, but I need to visualize the months so I was wondering how to get the data into the WebView so I can handle it using JavaScript. It would also be helpful if someone could tell me how to get it back out of the WebView.

The reason I need to get the data back, is because the user will be able to change the data in the WebView.

I hope someone can help me. If I haven't provided enough information, please let me know.

Post a Reply

Replies

Oldest  Newest  Rating
0 Rutger Benoot · April 11, 2015
The problem (which I haven't actually mentioned) is that it has to visualized using graphs, and those graphs have to be stacked. I've tried some things with a stackpane and bar/linechart but I can't seem to get it right, so the WebView would be the easiest since I still have some code I could reuse
0 Rutger Benoot · April 11, 2015
An image when the program was running:
/images/forum/upload/2015-04-11/86b961cfc56f645ad19f3029222abf04.png

What it looked like in JavaFX Scene Builder:
/images/forum/upload/2015-04-11/ab06c312196175375d0e5c27e6a80441.png
0 Rutger Benoot · April 12, 2015
I don't really know how to explain it, but I've found a solution for my problem:

JSObject window = (JSObject) webEngine.executeScript("window");

                    Klimatogram k = controller.getHuidigKlimatogram();

                    window.setMember("klimatogram", controller.getHuidigKlimatogram());
                        webEngine.executeScript("maakKlimatogram()");

and I've also found a very interesting video about the JavaFX WebView, if anyone ever needs it:
  • 1

Java / Android Development

129,754 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator