Skip navigation

Category Archives: NetBeans

In the example above, what does the Cancel button do? The answer is: it does nothing. Clicking on it opens the application anyway. So, why call it cancel? OK could have been much better.

I have been dabbling with Grails of late, for a pet project. NetBeans comes with a sufficiently usable support for Grails. The other day, while installing a plugin using NetBeans, I stumbled upon this confusing UI. For anyone who has worked with the Grails command line, the list of plugins is self explanatory. However, what got me was the way to install the plugin once I select it in the list.

NB Grails Plugins Dialog

See that ‘Install’ button there? It is so close to the plugin location field. It doesn’t catch your eye since it somehow feels related only to the plugin location field. Also, the dialog poses questions to me when I look at it, questions which can only be answered by trial-and-error, which is bad:

“Am I able to select multiple plugins from the list and install them with one click?”

Turns out that I can’t. Then again, not many folks need to install many plugins in one go. But some indication might have helped. You see, GUIs are supposed to be one up over command lines, so I was assuming multi select is possible, only to try out and find it otherwise.

“Am I able to select a plugin from the list and specify another plugin’s location in the field and install both of them with one click?

Again, an extremely rare use case. This is very similar to scenarios you might have while installing NetBeans plugins themselves and the UI there makes it very clear what can be done simultaneously and what cannot be. Below is the screen shot of the NetBeans Plugins Installation UI.

NetBeans Plugins UI (Manual Install)

NetBeans Plugins UI (Update Center)

As can be seen above, the NetBeans Plugins UI has two tabs – one for plugins available from the update center, and another for installing plugins from your hard disk.

And since NetBeans is an open source project, the action item for me is to check out the sources, implement the fix and submit the patch for evaluation and inclusion into NetBeans 6.9. Stay tuned for updates.

The standard code used to display a dialog in NetBeans is:

DialogDescriptor dd = new DialogDescriptor(new UIPanel(), "UI Panel" ) ;
Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);

This uses the DialogDescriptor and DialogDisplayer classes from the Dialogs API. You end up a dialog which looks like the image below.

However, what if you want to display some notification messages to the user? NotificationLineSupport to the rescue. Just create a notification line (code highlighted below) and add your message.

DialogDescriptor dd = new DialogDescriptor(new UIPanel(), "UI Panel" );
NotificationLineSupport supp = dd.createNotificationLineSupport();
Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
supp.setInformationMessage("Sample Information Message" );

The result is a dialog like the one shown below:

You can show informational messages, error messages and warning messages. However, displaying an error or a warning message does not disable the OK button. For that you will have to call the setValid() method.

Since I have been going after some low hanging fruits in fixing some Python support related issues in NetBeans, strictly over weekends (without the knowledge of my wife who prefers my MacBook Pro being 2000 miles away from me on weekends), I ran into an interesting issue where I had to display the NetBeans font chooser instead of a custom font chooser being used in the code. Unable to find the proper API (perhaps I am dumb), I waded into the NetBeans sources, and found the way out. Blogging about this here to save some poor soul some time when the need arises.

PropertyEditor pe = PropertyEditorManager.findEditor (Font.class);
DialogDescriptor dd = new DialogDescriptor (
    "Some Title"  // NOI18N

DialogDisplayer.getDefault ().createDialog (dd).setVisible (true);
if (dd.getValue () == DialogDescriptor.OK_OPTION) {
    font = (Font) pe.getValue ();

It just boils down to getting a property editor for Font and then wrapping the panel inside a dialog box using the NetBeans DialogDisplayer API.

I am a big Ubuntu fan, and always feel a bit sad when I have to upload my new and noteworthy screenshots next to the swanky and sleek screenshots of people on a Mac on the NetBeans wiki (look at the Spring framwork support section here).

However after some digging around I finally got a font combination that looks pretty neat to my eyes. Here’s a screenshot with the default font in NetBeans 6.1 running on Ubuntu 8.04:

And here’s after I changed the font to Bitstream Vera Sans Mono 12 pt:

The second one is much better for my eyes (atleast). Any other good combinations out there folks?

Font Settings:

It was a long weekend here in India, and that provided me some time to add some shortcuts which will help users who author XML documents using NetBeans. I wrote a plugin which will add some context sensitive actions to the XML editor. I have just managed to add one action (Delete current attribute), but more are on the way. Actions planned are:

  • Jump to parent tag
  • Jump to next sibling tag
  • Jump to previous sibling tag
  • Jump to end tag (if at start tag)
  • Jump to start tag (if at end tag)
  • Jump to next attribute in a tag
  • Jump to previous attribute in a tag
  • Delete current tag (alongwith children)
  • Delete current attribute (alongwith it’s value)
  • Delete value
  • Expand a short tag <a/> into the longer form <a></a>
  • Condense an empty tag <a></a> into it’s shorter form <a/>

I am planning to upload the module on the Plugin portal soon. For now, here’s a screen shot:

Before the action was selected:

After the action was selected (notice the name attribute is gone):

NetBeans never boasted of a good editor as compared to IntelliJ IDEA and Eclipse, but things took a complete turn when NetBeans 6.0 came out. And now that NetBeans has conquered Java developers with the shining new editor, NetBeans is going gung-ho for Groovy, Scala, Erlang and what not. Though I totally agree to Groovy and Scala becoming first class citizens in the NetBeans world, I personally feel that NetBeans needs to do something about nicely editing a 10 year old thing – XML.

Why, you might ask. Well, whatever web frameworks I have dealt with, Struts, Struts2, Spring MVC, JSF, require reasonable amount of configuration in XML. Hell, even many non web applications seem to use Spring and it’s XML configuration files. Though the deal is now seeming in favor of POJOs with annotations, I don’t think developer authored XML is dead, by any means.

In a series of upcoming posts, I plan to compare the XML editing landscape in Eclipse, IntelliJ IDEA and NetBeans. IMO, NetBeans has the weakest XML editor story, but I plan to make a wishlist out of this, hopefully someone will come along and take XML editing in NetBeans to new heights.

I was trying out IntelliJ IDEA 7.0 and came across the XML breadcrumbs feature. The breadcrumbs bar tracks the current position of the cursor in the XML tag hierarchy.


It would be so nice to have this in NetBeans. So here it is (sources to be uploaded soon):

After my last adventure with XML code completion, I am ready for one more nifty add-on. This one is straight from Eclipse XML editor. When you request completion for an attribute in an XML tag, you might want to add the default value (by default). Such a thing is not provided by NetBeans. However, as with yesterday’s hack, this one is mighty easy to do.

If you have followed yesterday’s post, you know where the sources of the schema aware code completion module reside. When we type CTRL+SPACE for invoking code completion for attributes of a tag, we get a list of org.netbeans.modules.xml.schema.completion.AttributeResultItem objects, each one representing a possible attribute that can belong at the position where completion was invoked. I make the following modifications to the code.

First, I need to find if there is a default value for the particular attribute. So, I add the following code to the constructor of AttributeResultItem:


The getDefaultValue() method is as given below: 


 One final thing. The getReplacementText() method needs to be modified.


That’s it. Now, when you invoke code completion for attributes (after you have compiled your changes and re-run the development IDE), you can see the attributes with their default values.



More XML completion fun to come in the next post! 

If you are used to heavily editing XML files in NetBeans, you would have wished for the code completion assistance to be a bit smarter. As an example, let us take the case of editing a Spring Framework Beans Configuration file. I want to add an <alias> tag to the XML configuration file. This tag has two required attributes: name and alias. It all starts by invoking the code completion assistance by typing in ‘<‘. The following dialog shows up:


When I select the alias tag and hit Enter, the completion assistance just puts in the tag name:

To insert the attributes I have to again press CTRL + SPACE:


If the code completion were a bit smarter, it would insert the required attributes as well. I mean, why will anyone use a tag without using the required attributes? Anyway, NetBeans doesn’t offer this feature, so I decided to do some hacking.

I downloaded the NetBeans sources and opened up the module project for the Schema based code completion in NetBeans (NB_SRC_ROOT/xml/schema/completion)



The items displayed in the completion assistance popup are implemented in and Since I want additional text to be added when the user wants to add a new XML tag (element), I will modify the I modified the constructors of the class to add the additional text:


I needed to override a method to return the new text to the completion infrastructure.


That’s it. Now I built NetBeans, and run the same scenario for code completion, and here’s what I see:


Notice the required attributes appearing alongwith the end tag (another nifty thing which the current XML code completion misses). Now pressing Enter gives me the tag complete with it’s required attributes and end tag.


The hack still needs some work, but you can see the point. If there is something you want in NetBeans, just dig through the sources and modify it and contribute it back to the community. This in my mind is the single most advantage of using an Open Source tool.