Over a million developers have joined DZone.

Beefed Up Code Navigation Tools in NetBeans IDE 7.2

DZone's Guide to

Beefed Up Code Navigation Tools in NetBeans IDE 7.2

· Java Zone
Free Resource

The single app analytics solutions to take your web and mobile apps to the next level.  Try today!  Brought to you in partnership with CA Technologies

A powerful yet subtle feature of NetBeans IDE 7.2 is the significantly enhanced search functionality that this release provides.

Of course, the NetBeans IDE 7.2 performance boost itself can also be considered to be relevant in the context of searching, since navigation actions have been specifically focused on in relation to performance enhancements:

The indexes and indexing infrastructure were rewritten to use transactions. The project scanning and up to date check do not block editor features nor navigation. These features use the previous committed index. Also the write transactions are suspended by read transactions, so the background indexing has lower priority than user actions. From http://wiki.netbeans.org/NewAndNoteworthyNB72

However, let's take a look at a range of new tools that have been added to NetBeans IDE 7.2 to let you find the code you need, much faster than in previous releases.

First of all, there's the much trumpeted FindBugs integration (YouTube movie here), enabling searches across multiple projects to identify specific problems in your code.

However, there's more to it than FindBugs as such because FindBugs plugs into the new pluggable analyzer functionality, into which you can plug too because there is an API for that purpose in the works. (A quick start scenario for this is here.) That means FindBugs is only one example of the kind of analysis that can be done. You could, for example, integrate HTML Tidy in a similar way.

But let's move away from the FindBugs-related features to focus on the lower-level, less well known file search features available in NetBeans IDE 7.2. (The next two screenshots can be clicked to give you a better view of the tools under discussion.)

As you can see, above, there is, for the first time, code completion in the Find tool. The code completion offers matching words used within the current file. But take note of a couple of things. The code completion isn't a plain text search. Semantic knowledge is built into it, otherwise the final item, assuming spaces as separators, would have been "wiz.putProperty", since those are the characters referred to on line 64 in the final item in the code completion list. And take a look again at that particular item: it refers to characters found in the comments of the code, which is really nice. Finally, since the "p" I entered was a lowercase, the first selected item is the first item starting with a lowecase "p". Had I entered "P" instead, then "Panel" would have been highlighted in the list above. (By the way, also note that the Debugger now has enhanced code completion support too, from NetBeans IDE 7.2 onwards.)

Next, once you've found a piece of interesting code, you might like to bookmark it, by pressing Ctrl-Shift-M, followed by Ctrl-Shift-Period and Ctrl-Shift-Comma to navigate forward and backward between your bookmarks. In NetBeans IDE 7.2, the new menu item Window | Navigating | Bookmarks brings you to a brand new window, named "Bookmarks". Here you can, for the first time, manage your bookmarks. For each line you bookmark, a new item is automatically added in the Bookmarks window. Double-click an item to open the related file and the cursor will land on the specific line you bookmarked. You can rename bookmarks in the Bookmarks window, to make the display text more useful, rather than simply displaying the file name and line number. You can also quickly see, in a small window to the right of the bookmarks, what code is being referenced. Multiple bookmarks in multiple files across multiple projects can all be managed together via the new Bookmarks tool:

And, best of all, when you restart the IDE, your bookmarks will still be there because the content of the Bookmarks window is persisted across restarts.

How is all this different to earlier release of NetBeans IDE? Well, there was no Bookmarks window. You could jump from bookmark to bookmark within a file, but not across files, or across projects, as you can now do via the Bookmarks window. Also, a restart of the IDE would wipe out all your bookmarks, which made the bookmark functionality a lot less useful than it now is.

Thus far, we've looked at search & navigation tools that are mostly useful within files. Now let's look at brand new search & navigation tools to be used within and across projects. When you press Ctrl-F on any node within the Projects window or Files window, you always get the "Find in Projects" dialog:

Above is how the "Find in Projects" dialog looks prior to NetBeans IDE 7.2. From the 7.2 release onwards, you have this dialog instead:

After you spend some time trying to spot the differences between the two dialogs above, here's a list of them:

  • Search in Archives. Include JAR, ZIP and other archive files in the search scope.
  • Search in Generated Sources. Include generated source files in the search scope, such as the "build" directory or code generated by "wsimport".
  • Use Ignore List. Use a list of files to ignore when performing the search. Click edit to open a dialog where you can add or remove files and file paths from the ignore list, as shown below:

    Here in the New & Noteworthy you can see how path patterns can be added to the ignore list, with the help of a regular expression checker.
  • Search Scope. The scope of projects to search. You can either search the projects you selected in the Projects window or all open projects. What's interesting about the search scope is that, in addition to what you might expect, i.e., in addition to "all open projects" and the "selected project", you can also search anywhere you want to search on disk:

    Then, as in this case, you could select anything you like, such as my NetBeans projects folder, and search for anything I'm interested in within that folder:

    Above, I'm searching in a folder named "NetBeansProjects" for the above file name pattern. So, since I have dozens of Anagram Games lying around in that folder, I get lots of files returned from the search, which I can sort by a variety of different criteria, in this case, sorted by date:

    Note that this search doesn't only look inside NetBeans project folders. Any folder you select on disk will be search, and very fast indeed, for files matching the pattern you provide. In that sense, the "Find in Projects" dialog is usable way beyond the scope of NetBeans projects.

    As the icing on the cake, there's even a new Search API in the works, which will let you extend the "Find in Projects" dialog with your custom search requirements, maybe for your own project type for example. (A quick start scenario for this is here.)

In short, your ability to find the file you need to work with has been massively enhanced with a range of brand new tools. Coupled with the performance boost of NetBeans IDE 7.2, which is positioned as its main feature, your code is now really at your finger tips, more than ever before.

CA App Experience Analytics, a whole new level of visibility. Learn more. Brought to you in partnership with CA Technologies.


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}