views:

52

answers:

2

I would like to know if there is a way to modify the template that NetBeans uses to generate the code for JFrame while designing it, specificaly the order. As you know NetBeans generates code for JFrame form as follows:

  • class declaration
  • constructor calling initComponents();
  • initComponents() method (folded & locked to editting)
  • main method declaration
  • variables declaration (for JFrame components like JPanel, etc., also locked)

and I would like to change the order of these parts of the code. It's just a matter of habbit. I like the variables declaration part to be at the beginning not at the end. I'm well aware that it won't change the functionality of my application probably in ANY way. However I am using NetBeans designing tools just to establish my GUI and rest of the code I write myself.

Thanks for help!

A: 

I do not think that it can be changed in any way directly from netbeans, but what can you do is that you exit the IDE, find the .java files of the classes you want and open them in some not so basic text editor (something like Word Pad should do the trick. You can use Notepad for instance, but usually the code tends to be displayed in one single line, which is not very readable). So basically you edit the structure of the code from the Word Pad, save it and re open it. That should do the trick.

npinti
all right, but for that purpose where do I find the actual template file for JFrame. I've been looking for it and wasn't much successful finding it.
Martin S.
+1  A: 

Tools > Template , then find the template you want to modify, then choose open in editor. Then, save. There is also an add button in the template dialog, if you want to add some templates yourself.

The template for JFrame is under Swing GUI forms folder.

See this link for detailed reference, including the keywords you can use for the template (like ${name} inserts the filename, etc)

Edit: To modify the locked part of the original JFrame template, Duplicate the original template, find the duplicate in your netbeans config, like C:\user\.netbeans\6.8\config\Templates\GUIForms then edit the template using an external editor

Louis Rhys
but that won't allow me to unlock and move to locked part for obvious reasons, will it?
Martin S.
ok see my edits
Louis Rhys
Templates folder doesn't exist neither in C:\Users\<username>\.netbeans\6.8\config folder nor in any other folder within .netbeans folder
Martin S.
are you sure? It should. Is that before of after you click duplicate (the original template does not appear here)? Which version of netbeans do you have? did you find the .netbeans folder? what is the netbeans_default_userdir value in C:\Program Files\NetBeans x.x\etc\netbeans.conf?If you still can't find it then you should follow the instructions [here](http://platform.netbeans.org/tutorials/nbm-projectsamples.html), because copy-and-pasting did not work for Forms template
Louis Rhys
Another way to find the folder is by duplicating, then rename it into a weird (unique) name, such as a random sequence of characters, and then use windows search to find it
Louis Rhys
are you sure? Yes ### Is that before of after you click duplicate? Neither ### Which version of netbeans do you have? 6.8 (Build 200912041610) ### did you find the .netbeans folder? Yes, I did ### what is the netbeans_default_userdir value The same where I found .netbeans folder ### Another way to find the folder is by duplicating, then rename it into a weird (unique) name. Already tried that, didn't work either... :-( ### I'll try follow the link.
Martin S.
hey, the Templates folder suddenly appeared there. What a shame that there are thing that can't be modified :-( thx though
Martin S.