Monday June 04, 2007
Sample for Registering Palettes in Layers
There've been lots of questions recently about the new 6.0 functionality that allows you to register palettes in the layer file. Previously, the palette had to be created in the editor's constructor. Now, since it can be registered in the layer file, you can create a palette in a different module to where the target editor is found. The most applicable scenario seems to me to be the one where you want to create palette items for Java source files. In the past, you'd have to patch the NetBeans sources that define the Java editor. Now, you can just register the palette in the text/x-java folder and it will appear, as if by magic, when a Java source file is open.
To see the mechanics of the above, go here:
Java Source File Palette Sample
Install the NBM you get there, open the New Project wizard, and then you'll have this new sample, which is self-explanatory:

Once the sample is installed, you get a palette with the one 'Main Method' item:

Then, once you've established that it works (i.e, drag and drop an item, type in a comment, and note the code that's generated when you click OK) you can inspect the sample's code and learn from it, and adapt it for your own purposes. Make very sure you have the latest build you can get, because bugs have been fixed in this area very recently. If the sample doesn't work for you, the chances are that the reason is that you don't have the latest build.
Jun 04 2007, 08:59:02 AM PDT Permalink


