28

Those HTML5 websites look great - why don't my Java desktop apps do? Swing and SWT are, well, just old-school. They do their job, but to create fancy looking GUIs with animation and everything is merely impossible.

I was wondering: Is it possible to use HTML5 as a GUI toolkit? I'm having a library in mind that has an API similar to Swing or SWT, but renders in HTML5. It should be themable and you should have access the the page in Java (i.e. some fusion between Java and JavaScript/HTML5).

Why not just create a web app and send my users the URL to it? I would like to benefit from real Desktop integration of Java SE apps (Files, COM, Tray Icon etc.). Just something like PhoneGap but for desktop OS'es instead of phones.

Stunningly I did find nothing like that on the web. But maybe I just entered the wrong search terms? Anyone have an idea?

Or if not: Can I somehow embed WebKit/Chrome together with my app? So the user won't have to install its own copy, or change any settings.

Mive van Haaven
  • 281
  • 1
  • 3
  • 3
  • It's not impossible at all; you have essentially unlimited power. If you mean "*free* nice LaFs", or "fancy functionality where I don't have to code", that's different. But hardly impossible. – Dave Newton Feb 10 '12 at 21:34

5 Answers5

9

Two things come to mind:

  • Adobe Air, which is more or less exactly what you're looking for: PhoneGap for the desktop.
  • Chromium Embedded Framework, which, with a little effort on your part, would allow you to use Chromium as the frame for an application.
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
Mike West
  • 5,097
  • 25
  • 26
5

You should check out JavaFX 2.0. It allows you to specify GUI components in FXML, and supports CSS styling. It also has a "WebView" component that allows you to easily display web pages within an application.

EDIT 28th of November, 2015

The JavaFX Overview Section has moved.

As of JDK 7u6 JavaFX is included with the standard JDK and JRE bundles. Please download the JDK or JRE to use JavaFX.

If you are looking for the JavaFX Scene Builder download you will find it in the "Additional Resources" section of the main Java SE Download Page.

Please update your links to the new location.

Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
alistair
  • 1,164
  • 10
  • 27
2

One of the ways of utilizing HTML / JavaScript in desktop applications is embedding an HTML server in the application. Then a web page will be the GUI. It is literally a few dozens lines of code if you use

Example: simple HTTP server in Java using only Java SE API

Docs: http://docs.oracle.com/javase/7/docs/jre/api/net/httpserver/spec/com/sun/net/httpserver/package-summary.html

You need to serve the GUI web page from the web server (even on the localhost) to avoid JavaScript same origin policy conflict described here

Community
  • 1
  • 1
34n
  • 29
  • 1
2

Some time is passed so I don't know if this can be of some use. But you might have a look at DukeScript (http://wiki.apidesign.org/wiki/DukeScript), a concept from the original authors of the Netbeans IDE. As far as I could understand, the idea is to develop Java applications in an HTML5 environment. It relies on the browser as a platform (Chrome is supported) and on a JVM in Javascript that run inside the browser (really two of them, their own bck2brwsr and TeaVM). You can even use JavaFX, and you can deploy to Android, iOS or browser. Have a look at http://dukescript.com for examples.

Pietro Braione
  • 1,123
  • 8
  • 22
0

What advantages would you expect as opposed to a HTML gui in a standard browser? Lots of programs out there come with their own HTTP server for semplicity of UI develpment. I also read of QtQuick (YouTube demo) but really never tried myself

I have the following things to point out

  1. Debugging/testing the GUI is simpler in a browser
  2. Smaller package
  3. Development time optimization
  4. Truly cross platform (at least, it's easier to go cross platform when you have a HTTP server as the application logic processor)
Raffaele
  • 20,627
  • 6
  • 47
  • 86