Integrate Your Java Application With The Desktop

It’s been a number of years since I attempted to do Java desktop integration, and back then I depended on the JDesktop Integration Components (JDIC) project to provide a platform-independent interface to native web browser.

I needed this functionality again recently, and checked back in on JDIC, only to find that the project never made it to 1.0 release status, and hasn’t been updated in over two years.

Fortunately, with a bit more research, I found that as of Java SE 6, most of the JDIC functionality has been built into the new java.awt.Desktop class.

The documentation is pretty good, so here just a couple small examples to whet your appetite.

Desktop desktop = null;
if(Desktop.isDesktopSupported()) {
   desktop = Desktop.getDesktop();
   desktop.browse(new URI("http://greybeardedgeek.net"));
}

 

:::java
Desktop desktop = null;
if(Desktop.isDesktopSupported()) {
   desktop = Desktop.getDesktop();
   desktop.edit(new File("someFile.txt"));
}

The Desktop class supports browsing and editing as shown above, as well as printing, opening a file with its associated application, ane creating a new email in the native email client. If you’re looking for JDIC’s old System Tray functionality, that’s in the java.awt.SystemTray class.