Bypassing Lock on Generated Code in NetBeans 6.5?

Allain Lalonde picture Allain Lalonde · Jan 16, 2009 · Viewed 20.2k times · Source

In NetBeans the GUI Builder generates code that is off limits to you from the editor.

I know you can switch to Design Mode and specify custom code and then enter edit in indirectly that way, but it's a pain to not be able to edit text that's 2 lines from your cursor.

Can I allow editing within those regions... I promise I'll be careful :)

Thanks.

Note: I don't want to lose code generation

Answer

Michael Myers picture Michael Myers · Jan 16, 2009

If you open the .java files in Notepad or WordPad, you'll find pairs of comments that say

// GEN-BEGIN: <name of section>
...
// GEN-END: <name of section>

Delete those comments, and two things will happen.

  1. You'll be able to edit anywhere in the file in NetBeans.
  2. NetBeans will not be able to regenerate the file from the GUI editor.

So it can be done, but don't do it unless you really mean it.


EDIT: "Note: I don't want to lose code generation." Ok, let's see here.

  1. You want to change what is generated.
  2. You don't want to lose code generation.
  3. You don't want to use the facilities NetBeans provides for adding custom code.

It sounds like you're wishing yourself trouble. :D