Hidden NetBeans Feature: Drag/Drop to Create HTML Snippets

Here's another super hidden NetBeans feature. Because of the inherent functioning of this feature, it is completely hidden and undiscoverable from the point of view of the NetBeans user interface.

The scenario is that you've got an HTML file open and you're typing something in there. The 'something' is something that you're likely to reuse within the same HTML file or other files, such as the META tags that you see highlighted below:

Now, as you can see, I have the part of the file that I'd like to reuse highlighted.

And then... I drag my mouse into the palette, i.e., the palette that you see on the right of the image above. And then, guess what? This dialog automatically pops up:

The "Content" section above is automatically filled in, based on what I dragged. The other fields and icons are things I fill in myself. Then I click "Add to Palette", at which point the HTML snippet is added into the palette, from where it can then be dragged into an HTML file, like any other snippet in the palette.

Handy, isn't it? And really hidden. (I blogged about this before here in 2008, where you also see a Java file equivalent.)

In other news. There are two excellent new NetBeans blogs out there! The first is NetBeans Ruminations by Hermien Pellissier from South Africa and the other is the NetBeans category of Crazy Java Hacking by Martin Skurla from Slovakia. Check them out! Their blog entries are also going to be visible in the NetBeans welcome screen, because they've been included in the planetnetbeans.org aggregator. You have a NetBeans related blog too? Leave a message here. And if you don't have a NetBeans blog too, why not start one?


Interesting, Thanks for sharing.

Now, is this better than creating an include file?

Posted by jn on January 27, 2012 at 08:39 AM PST #

Excellent. Never knew of this feature. Maybe came new to 7.1.
That's gonna be helpful if it works also for xhtml files as I use them all the time.

Posted by Hanynowsky on January 27, 2012 at 11:41 PM PST #

Hi Geertjan
I've a NetBeans related Blog: http://anchialas.wordpress.com/
Perhaps you can add it to planetnetbeans.org?
Thanks, Anchialas

Posted by guest on January 30, 2012 at 05:23 AM PST #

Thanks for the clarification.
Damned near impossible to find out how to add a new snippet without using the drag-and-drop.
Seems the Palette must be docked open for this to work.

Posted by Joel on July 09, 2013 at 12:02 PM PDT #

It is really helpful to cut development time.

Posted by Rifki on November 25, 2013 at 02:01 AM PST #

Sound like a good but unfinished feature

It will be much better to have a button <add / edit your snippet>

As far I can see you can't edit your snippet after creation - but
having a button for add / edit snippets - would be a real life saver .. after I've read your article - I've created few snippets but later I was not able to edit my code clips ...

Furthermore, why not a HTML5 palette with a collection of basic html5 tags: header - footer - section - article - nav - aside - canvas - video ...etc (why not ?)

A css3 edit box is a real need - a place where users will prepare their rounded css buttons / background gradients / drop-down menus / etc. But this is another story for another topic ;)

Posted by guest on February 09, 2014 at 04:08 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed

Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« July 2016