Bypass locking generated code in NetBeans 6.5?

In NetBeans, the GUI Builder generates code that does not meet your requirements from the editor.

I know that you can switch to development mode and specify your own code, and then indirectly enter the change, but it’s a pain so that it’s not possible to edit the text that 2 lines from your cursor.

May I allow editing in these regions ... I promise that I will be careful :)

Thanks.

Note. I do not want to lose code generation.

+4
source share
10 answers

If you open it in an external editor, there are two possibilities:

  • there is no guarantee that your changes will work (and not break anything) in the Netbeans UI Editor
  • The next time you edit a file in Netbeans, it will be regenerated.

In any case, perhaps not what you want. The best thing would be to do the whole design in the gui editor, and when you are satisfied with it, delete the comments and continue.

[sarcasm] With the drag-and-drop gui editor, what would you like to change manually? [/sarcasm];)

+4
source

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

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

Remove these comments and two things will happen.

  • You can edit anywhere in a file in NetBeans.
  • NetBeans will not be able to recover the file from the GUI editor.

So it can be done, but not done, unless you really mean it .


EDIT: "Note: I do not want to lose code generation." Ok, look here.

  • You want to change the created.
  • You do not want to lose code generation.
  • You do not want to use the tools that NetBeans provides to add custom code.

Sounds like you're sorry for the trouble.: D

+4
source

I had the same problem. I extended JPanel with my panel class, and I was unable to package it with the rest of the user interface. At first I searched the Internet and I found your question. I could not find an elegant solution to this problem. So I decided to create another java class and copy the NetBeans code into it. It worked like a charm. I agree, it would be nice if we could modify the existing code, as in .NET.

+2
source

I copy the initcomponents () method, create my own newInitComponents () method, inserting the generated code and overriding what needs to be redefined before distributing the code. Thus, when changes are made to the editor, you can still copy the code into your new method. You maintain functionality without spending the ability to redefine where you need it. Just call newInitComponents () in your constructor, not in the original. This is not the most effective way to do something, but it does what you want.

+1
source

You can also try moving the .form file to

(project name) \ src \ (JFrame / JPanel name) .form

Now NetBeans will see it as a .java file.
If you have not edited anything that is necessary for the GUI editor, you can move the .form file back to the src folder.

+1
source

Can you subclass the class and override the method where this code is? Of course, you will have to support this method over time when you make changes to the GUI.

Perhaps you can also look at AspectJ. It will modify the byte code at build time and make the changes you define. Not sure if this gives you enough control over which code needs to be changed.

0
source

If you use APT , you can rewrite the source code at compile time. Thus, you can rewrite the code that is currently available. You can save the new code in a single Java file along with comments to explain what is happening. This tutorial makes it easy to get started. Copy this code, make it work, and then customize it to your liking. To find out where in the code the annotated method is a call to getPosition () in the Declaration.

0
source

Go to the design page and select any of the fields. Right-click on any selected field and select Customizer Code, Custom Code Code, change all default code to custom creation. Now you can edit your design code as you like ...

0
source

Very simple ... crappy UTF-8 did not allow me to compile one JasperReport (everything was done using the GUI). So, I needed to change the project to iso-8859-1. Result? The project is confusing, and some of the things that need to be fixed are in the blocked parts of the code. So I really need to edit these automatically created parts. When they are restored, they will be fine, because the project is now iso-8859-1.

0
source

Step # 1 Close the project in NetBeans

Step # 2 Remove the .form File from Your Project Source Directory

Restart the project, and now it will be available for editing!

0
source

All Articles