Geertjan's Blog

  • March 29, 2006

Code Snippet Creation in the IDE

Geertjan Wielenga
Product Manager
Something that I've been waiting for for many a month has finally come to pass... you can create your own code snippets in NetBeans IDE. Pictures speak thousands, so here's the picture that reveals everything:

First, ignore the Wicket window on the right hand side. That's not what this blog entry is about. Instead, look at the small window at the bottom left of the screenshot. That's right, the one that has the label "Code Snippet Window". All you need to do is right-click some code in the editor (as you see me doing in the screenshot) and then you choose Add Code Snippet. And then this dialog box appears:

You fill in the values and then a new item is added to the Code Snippet Window. Then, when you double-click the item in the Code Snippet Window, it appears at the cursor in the Source Editor.

You can get the plug-in module that provides this feature (along with some other plug-in modules that I haven't looked at yet), by registering Gregor Kovac's brand new update center:


He's still working on the plug-in module. For example, you can't delete or rename or edit code snippets. And they aren't persisted (when you restart the IDE, they're gone). But he's working on it! And, as you can see, the code snippet window is useful already.

Finally, in a future release of the IDE, I imagine that Gregor's idea will be implemented within the Component Palette. You'll be able to select code and then add it as a new item in the Component Palette (not, as in Gregor's plug-in module, within a separate window). In fact, I recently talked to the engineer who works in this area of NetBeans and he told me that he's planning to do exactly that. However, in the meantime, I'm already using Gregor's work. I think it's great.

Join the discussion

Comments ( 2 )
  • Sandip Wednesday, March 29, 2006
    Check out the Code Template Tools Module which I create a few months ago:
    Allows you to create and insert code templates with template variables. The advantage is that code templates can have variables.
  • Charles Ditzel Wednesday, March 29, 2006
    Java Studio Creator has had this in it for some time. I like their implementation but will have to look at Sandip's and your versions. Then I have to look at Wicket. With one blog entry you really give me alot to look at, Geertjan!
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.