Geertjan's Blog

  • February 24, 2007

JDIC Browser on the NetBeans Platform

Geertjan Wielenga
Product Manager
A completely unexpected thing that came out of NetBeans Day, for me, is that I now have my own JDIC browser integrated in NetBeans IDE. In fact, I am typing this blog inside a TopComponent. All the way back on November 1, 2005, I was already able to do this (and was pretty excited about it). But, in that case, I used an implementation of JDIC by Rich Unger. Now, however, I've done it myself. It all started yesterday when I was going through the list of names and e-mails that I had gathered from various people I had met at Sun Tech Days Hyderabad. One of them, who I briefly talked to after NetBeans Day, was from Aswin. He had left me the URL to his blog. So I went there and browsed around a bit. And guess what I found? A very cool blog entry by Aswin called Two Minute Web Browser in Java. In this really cool blog entry, Aswin shows how easy it is to create a JDIC browser in a Java application. It was really tempting to... begin thinking about porting his application to the NetBeans Platform. And so I did.

First, I built the application he described. Really cool, nice, clear and wonderful. It required virtually no coding. However, I encountered problems that many others had before me. For example, I ended up using the IE version of the embedded browser, which has problems with scrollbars, as you can see here... no horizontal scrollbar to be seen:

However, it wasn't long before I had done a 'simple port'. In other words, I moved the code into a NetBeans API TopComponent, and put the jdic.jar and native libraries in a library wrapper module. I also added 'Back', 'Forward', and 'Refresh' buttons, which were easy to program because of methods provided by JDIC. Here's the result, which I was already happy with, despite its limitations:

Note that I put the text field and buttons below the returned web page, instead of the normal place, which is above it. Why? Because of the lightweight/heavyweight component problem, which resulted in the drop-down list not rendering correctly, being hidden behind the returned web page. I looked around for solutions, and have found some, but just haven't implemented one yet. In the meantime, I moved the controls to the bottom of the browser, so that there wouldn't be a problem using the browser.

The next problem was that I was using JTabbedPanes, just like Aswin's original. However, there is no way of closing an individual tab. Normally, one would expect one of those little X symbols, which need to be clicked to close a tab. Both Joerg Plewe, who is a NetBeans Dream Team member, and Kirill Grouchnikov have blogged extensively about this issue. I initially adopted Kirill's approach, which meant I had to install the Substance look and feel. This was the result:

I was pretty happy with that, at least now I could close the tabs. However, I had reached the limitations of my 'simple port'. Everything was working in my TopComponent, but I hadn't leveraged anything else of the NetBeans Platform. I then began using more of what the NetBeans Platform has to offer, spreading out the ui more logically across the 'real estate' of the IDE. So, now, as a result of these additional steps, a new instance of a TopComponent opens, whenever I press enter in the text field afer entering a valid URL. And, good news, each instance of the TopComponent has its own X sign, as well as many other out of the box features, so this is a much better option than sticking with the JTabbedPane. However, within the TopComponent I still have a JTabbedPane. That seems to be the only container that can display a JDIC web browser. It is very odd. So now I have two tabs per web page, one from the JTabbedPane and one from the TopComponent. Not ideal, but still better than using only JTabbedPanes. So here's the result, with this blog entry used in the screenshot:

Note that here the controls (i.e., the text field and buttons) are in the toolbar, instead of being part of the TopComponent. And what you can't see here is that the status bar gives the user messages when the URL is invalid. In other words, this porting procedure has gone beyond the 'simple' TopComponent port, to a more complete transfer. Still far from complete, but clearly a functioning browser that is already 100 times better than the Swing browser that is bundled with the IDE. Notice that it is completely integrated in the IDE, so that, for example, you can flip from one browser page to a Java class, just like any other window in NetBeans IDE, for which no coding was necessary on my part:

Plus, it can be installed in any application built on the NetBeans Platform (and there can't be many that wouldn't benefit from a high quality web browser), although currently only on Windows operating systems. And it all came out of coming across Aswin's cool instructions for creating a small browser, out of a few lines of code. Thanks Aswin!

Join the discussion

Comments ( 14 )
  • Tom Corbin Saturday, February 24, 2007
    Wow, this looks great. It seems like a really neat addition to the platform, either as a netbeans tool or as a development platform tool.
    I read all you've been writing, but still haven't been tempted to investigate netbeans as a platform. I use it for development, and we are developing a swing application. But we heavily use spring and I'm just not sure how well that would integrate. Also, netbeans as a development platform doesn't do much to support spring. Which is strange, given it's huge mindshare.
  • Sandip Saturday, February 24, 2007
    1 - Very cool

    2 - For "Because of the lightweight/heavyweight component problem, which resulted in the drop-down list not rendering correctly, being hidden behind the returned web page." have you tried:


    3 - The JDIC Browser should/could be wrapped as a


  • Geertjan Saturday, February 24, 2007
    Sandip, these are excellent resources. Thanks so much, I will look at them and they seem like exactly what I need.
  • Rich Unger Sunday, February 25, 2007
    Were you just rewriting what I'd done previously as an exercise, or is there new code here? If so, please check it into the svn repository at jdic-netbeans.dev.java.net. I believe the code there already uses heavyweight popup menus to get around the lightweight/heavyweight issue.
  • Geertjan Sunday, February 25, 2007
    Hi Rich, purely an exercise. I will compare with yours and see if there is new code.
  • Geertjan Sunday, February 25, 2007
    And, not just an exercise, but an example of porting a Java application to the NetBeans Platform that I might use in a future presentation.
  • Gustavo Sunday, February 25, 2007
    I use an AWT Panel to host the WebBrowser. On the heavyweight/lightweight problem, yes, you can use setLightWeightPopupEnabled(), but this doesn't fix other problems: try to click on your Collaboration Sessions TC, minimized on the right, and this TC will expand \*behind\* the browser, until pinned. Maximizing and restoring the browser's TC containing breaks the layout, if other TCs are present. IMO, the JDIC browser is far from usable as a TC in Netbeans' window system, until the heavyweight/lightweight issue is solved. In real world Platform apps, I'm using the JDIC browser in its own dialog.
  • Geertjan Sunday, February 25, 2007
    Yes, Gustavo, you're right. But maybe Rich's JDIC browser solves this. I don't know for sure, haven't looked at his browser recently, but want to do so soon.
  • Rich Unger Sunday, February 25, 2007
    It's an open issue: http://www.netbeans.org/issues/show_bug.cgi?id=79130
  • Aswin Anand Monday, February 26, 2007
    Thanks a lot for using my app as the starting point :)... on the 9th cloud now!
  • Geertjan Monday, February 26, 2007
    Well, I was on that same cloud when I discovered that code in your blog!
  • Alex Monday, April 2, 2007
    I tried to do the same, making it a topcomponent on the palette, but despite following the help in the IDE, it didn't quite work. Perhaps you had to add the DLLs as well? Could you explain how you did this?
  • Geertjan Tuesday, April 3, 2007
    Yes, in the library wrapper module, make sure the "jdic.jar" is in modules/lib, the "jdic.dll" is in modules/ext. Also, put "IeEmbed.exe" in modules/ext, in the same library wrapper module, which works with Internet Explorer. There's also an equivalent for one other browser, I think. Any further help needed, please let me know. I will probably create a full scale tutorial on this scenario at some stage. However, you should now have enough instructions to set it up yourself.
  • Geertjan Tuesday, April 3, 2007
    By the way, the above instructions in the comment are for Windows only. Each operating system has different requirements in relation to JDIC.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.