简体   繁体   中英

How to change non-editable/generated code in netbeans

I want to change the non-editable code in Netbeans ,
I want to replace the
javax.swing.JTextFeild with ObservingTextField
for which I have a class imported into my project in order to Implement a date picker
But Netbeans Does not allow me to edit the code . Please help

// Variables declaration - do not modify                     
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
`private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;`
// End of variables declaration   

Another option delete the special comments. You can't see in NetBeans but if you open in other text editor (for example notepad) you will see that comments on the begining and ending of non editable section. The comments look like this:

//GEN-BEGIN:initComponents
//GEN-END:initComponents

If you want to add custom component to a file that uses the Netbeans GUI editor (called: Matisse), there are several ways:

First:

You could add that component to the "Palette" manager. I, personally, have had limited success with this, especially when adding components from my own, custom libraries. However, you can add components and just select "from a project", then select your project and you should see your component listed (if you don't, run a clean & build).

Notice in this project I have two files, CustomTextField and NewJFrame .

在此处输入图片说明

The code for CustomTextField is just something that extends a JTextField :

package test4;

import javax.swing.JTextField;

public class CustomTextField extends JTextField {

}

Then, in the Palette window, you right click and click "Palette Manager..."

在此处输入图片说明

Then in the Palette Manager, you click "Add from Project..." (if you are adding from a library, you click "Add from Library...", etc.

在此处输入图片说明

Then I select CustomTextField

在此处输入图片说明

And boom there it is in the Palette Manager, and I can drag & drop it into my GUI.

在此处输入图片说明

Note: this way is not very good if you need this component across multiple projects. The palette manager is for Netbeans as a whole, so if you try to use a component that exists in another project, you'll have trouble.

Note #2: I had problems with Java Web Start and my own custom library. There is a bug that was released with 7u25 that causes a NPE from the JNLPClassLoader whenever my custom libraries are loaded, so I had to import the components from a Project instead of a Library.

Second:

There is a more hackish way of doing things, but sometimes it's necessary: In the GUI-editor, you can right-click the component and click "Customize code."在此处输入图片说明 You can then change the variable definition ( not the declaration ). If you need to change the variable declaration , then it gets even MORE hackish, and I would recommend you just hand-write your code at that point. But, to do it through this window, you can "comment off" the portion in "variable declaration code" by adding /* and */ around private javax.swing.JTextField jTextField1; and add your own variable declaration.

Third:

Your other option is to hand write. :) If you need simple Swing components or components that can be added to the palette, I recommend the GUI Editor. If you need more complex and customized Swing components, then you'll want to start hand writing this code. Most people will recommend you do so anyways. I, however, proudly love Netbeans` GUI Editor.

It depends on WHY netbeans is preventing you from editing that source file.

  1. It is part of some library you just import into your project. This means your project is really using the compiled class/jar files. There is no point in editing this file. Find the author of the library and file a change request. This also applies for the java API itself. Of course the chances that they will actually accept the change request might be slim.

  2. It is write protected on the disk for no special reason. => make it writable

  3. It is controlled by some version control system which prevents editing before checking a file out of the system. Well check it out.

  4. It is some file generated by netbeans (which might actually be the case, judging from the source code you posted). In this case you probably can edit it in another editor (notepad/vi), but your changes will probably be overwritten on the next code generation, or break the file for whatever tools you use. => Find the tool and how to apply the changes appropriately with that tool.

Net beans let's you use custom code there from the form view page. I'm not on a computer with net beans right now but if you right click on the text area and its near the bottom

When you open a form file in netbeans, this point to the java file inteast of the form file.

The solution for edit this non-editable files is:

  1. Open Netbeans and go > Tools > Options > Miscellaneous
  2. Files Create new File Extension>form> and in Associated file mime select: HTML Files

I use a simple workaround to edit the file. First I copy the entire code in notepad and the I delete the class. Then I create a Java class and paste the code back. Keep in mind though you won't get the GUI builder now. So keep in mi

Easiest method to done it.

You can Simply done it by using ur text editor instead of netbeans. but few things to remind::::

1-Note the line of code in netbeans.

2-Close the netbeans IDE.

3-then open the file you want to change other text editor in your system.


In my case i need to change Registration.java file so i open it with text editor


4- Find the line of code you need to change

5- change the code

6- Save the file

Through this way you can done. Hope you will find the solution

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM