JDIC Browser on the NetBeans Platform

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!

Comments:

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.

Posted by Tom Corbin on February 23, 2007 at 10:11 PM PST #

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:

http://java.sun.com/javase/6/docs/api/javax/swing/JComboBox.html#setLightWeightPopupEnabled(boolean)

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

http://www.netbeans.org/download/dev/javadoc/org-openide-awt/org/openide/awt/HtmlBrowser.html

Posted by Sandip on February 24, 2007 at 03:20 AM PST #

Sandip, these are excellent resources. Thanks so much, I will look at them and they seem like exactly what I need.

Posted by Geertjan on February 24, 2007 at 04:24 AM PST #

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.

Posted by Rich Unger on February 24, 2007 at 05:45 PM PST #

Hi Rich, purely an exercise. I will compare with yours and see if there is new code.

Posted by Geertjan on February 24, 2007 at 09:30 PM PST #

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.

Posted by Geertjan on February 24, 2007 at 09:31 PM PST #

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.

Posted by Gustavo on February 25, 2007 at 01:51 AM PST #

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.

Posted by Geertjan on February 25, 2007 at 02:02 AM PST #

It's an open issue: http://www.netbeans.org/issues/show_bug.cgi?id=79130

Posted by Rich Unger on February 25, 2007 at 02:08 AM PST #

Thanks a lot for using my app as the starting point :)... on the 9th cloud now!

Posted by Aswin Anand on February 25, 2007 at 10:00 PM PST #

Well, I was on that same cloud when I discovered that code in your blog!

Posted by Geertjan on February 26, 2007 at 11:25 AM PST #

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? Gratefully, Alex

Posted by Alex on April 02, 2007 at 01:36 PM PDT #

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.

Posted by Geertjan on April 02, 2007 at 07:52 PM PDT #

By the way, the above instructions in the comment are for Windows only. Each operating system has different requirements in relation to JDIC.

Posted by Geertjan on April 02, 2007 at 07:54 PM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
12
13
14
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today