JDIC Browser on the NetBeans Platform
By Geertjan-Oracle on Feb 23, 2007
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!