Geertjan's Blog

  • July 9, 2007

Two Classes Every NetBeans API User Should Know

Geertjan Wielenga
Product Manager
There are two NetBeans API classes that are extremely important to know. They are useful in a very wide variety of scenarios. Here they are:

  • org.openide.filesystems.FileUtil. Provides countless useful methods that you absolutely cannot do without when creating NetBeans modules. Without question, my two favorites are FileUtil.toFile(FileObject fo) and FileUtil.toFileObject(File file). But, right now, since looking at that whole javadoc page, I see there's also a FileUtil.normalizeFile(File file), which seems pretty handy. Not to forget, of course, are the methods FileUtil.createData and FileUtil.createFolder, both of which can accept either a File or a FileObject as arguments. But, how about findFreeFileName and findFreeFolderName? No need to iterate through folders, looking for free file names, once you know these methods exist... and, more likely, no more ending up with files that are named "foo_1.java", because "foo.java" already exists. Anyway, that's what I assume will be avoidable with these methods.

  • org.openide.text.NbDocument. Without knowing about this class, you won't know about crucial editor methods such as NbDocument.findLineNumber(StyledDocument doc, int offset), which is vital when working with, for example, annotations. The methods runAtomic and runAtomicAsUser, used in various places in the "Rich Client Programming: Plugging into the NetBeans Platform" book, also come from this class, as do the methods for adding and removing annotations.

Various other utility classes are available for various areas, such as for code completion and code folding. Are there any specific NetBeans API classes or methods that you, NetBeans API enthusiast and reader of this blog, have found particularly useful? Has there been a moment where you thought: "Wow. Until I knew about this method, I was really doing things the hard way"? If so, I'd be happy to hear about it—leave a comment at the end of this blog entry and share your NetBeans API insights, large and small.

In other news. Jacek Furmankiewicz has created two extremely interesting looking plugins for OpenLaszlo and Echo2 in NetBeans IDE: nbopenlaszlosupport.dev.java.net and https://nbecho2support.dev.java.net. Congratulations Jacek, I am looking forward to trying them out!

Join the discussion

Comments ( 2 )
  • Markus Jais Monday, July 9, 2007
    Hi Geertjan
    thanks for this.
    just started reading your RPC book. I really like it.
    looking forward to your talk on Thursday in Munich at the Netbeans User Group meeting.
  • Jacek Monday, July 9, 2007
    Thanks for the mention, Geertjan...without your blog I don't think I would have mustered the courage to actually get my feet wet with NB module development...
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.