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
Go in the Design mode to the top window menu -> Windows -> Navigator . You will see Group "Navigator" popped up on the left (usually). Now you can delete unwanted variables (or edit them) with the right click menu.
If you right-click on the component in the Design View , and then click on " Customize Code " selection, you can modify the code in the InitComponent code.
Try this: Go to inpector view. Right click on your jFrame. Then in preview design select a L&F.
CTRL+SHIFT+H will open the replace dialogue where you can find+replace in any or all of your open projects.
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.
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.
It is write protected on the disk for no special reason. => make it writable
It is controlled by some version control system which prevents editing before checking a file out of the system. Well check it out.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With