Issue
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
Solution
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.
Answered By - ryvantage