Apr 242013
 

The NetBeans IDE’s debugging tools is one of maybe the top 5 features that I simply cannot live without! And as you can imagine, debugging is something I do quite regularly. So I was rather surprised when I only recently discovered an AWESOME feature that has been around for a long, long time. :) This feature is Variable Formatters.

To explain what a Variable Formatter is, some context is required. So lets have a look at the Variables window while debugging a very simple little Java application.

Variables Window

Variables Window

That is a pretty useful view. I can see all the variables that I could possibly need at a glance. (Of course, that is easy with an application this simple.) Of interest to this particular discussion, however, is the Value column. Notice how the various types have different string representations that are displayed. Now lets create a simple class called SomeObject:

public class SomeObject {

    private String var1;
    private String var2;

    public SomeObject(String var1, String var2) {
        this.var1 = var1;
        this.var2 = var2;
    }

    public String getVar2() {
        return var2;
    }
}

and create an ArrayList filled with SomeObjects, to inspect in the debugger:

ArrayList in the Variables Window

ArrayList in the Variables Window

Each of the elements in the list can of course be expanded to see the details. But what if you were looking for a specific element in a very long list? The great news is, that Variable Formatters allows us to customise how these items are displayed! From the main menu, select Tools > Options. Choose the Java page, and then the Java Debugger tab, Variable Formatters category.

Variable Formatters options

Variable Formatters options

A number of formatters are already specified, but we can add a custom one:

Custom Formatter

Custom Formatter

And very impressively, it gets applied immediately when you click OK on the options dialog! Even while the debugger is running! Now the display looks like this:

Customised Display

Customised Display

Suddenly ANY type of variable can have a user friendly, and customised, presentation in the variables window!

  2 Responses to “Getting More out of the Debugger”

  1. Awesome, I also use Netbeans for years now and didn’t take attention on the ‘Variable Formatters’ Options.
    Thank’s for sharing this..

  2. I realized that existed when a co-worker showed me why he liked the Eclipse debugger. I haven’t even thought about it and figured that Netbeans MUST have this feature (if not I was going to create a RFE)
    Then after a quick googling I knew it was there since a long time.

    Thanks for posting it.

 Leave a Reply

(required)

(required)


five − 5 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>