mixing technologies – osm + java + javafx

January 22, 2014

You’re looking at an interesting mixture of technologies. What looks like a standard web browser is in reality a JavaFXPanel set into a JTabbedPane and running in a JFrame. The web browser functionality is provided by javax.scene.web.WebEngine and javax.scene.web.WebView.The web engine in JavaFX comes bundled with regular Java 7, and is powerful enough that it can render just about anything a contemporary stand-alone browser can. What makes this powerful in this use case is the ability to create a thick client that I have complete programmatic control of, yet take advantage of Web 2.0 functionality (including powerful Javascript frameworks), including such services as Open Street Map. I can wrap my own very custom functionality around a web view (page) and reach into that view via Javascript-to-Java callbacks from the Web engine to add even more functionality. I’m sure there are limitations, and as I find them I’ll write about them. But for a first blush effort, which was nothing more than start up the SwingInterop.jar and paste in the URL to my local OSM stack, it shows considerable promise.

I know it’s fashionable these days to hate on Java, but (1) it’s old unpatched Java that’s the issue (and I’m talking years old, as in version 6) and (2) you’re an idiot to summarily dismiss current Java.

The source code for this Java/JavaFX application (SwingInterop) sample can be downloaded from Oracle’s Java pages. There are other JavaFX samples in the samples package as well.