How to modify/add code to the initComponents() method in Java using NetBeans?

Ahmad Farid picture Ahmad Farid · Mar 13, 2010 · Viewed 65.1k times · Source

How to modify/add code to the initComponents() method in Java on NetBeans? When I try to add any line of code this area seems to be like readonly and it's highlighted in gray! It's for security probably, but I suppose there is a way to disable that.

Answer

PeterMmm picture PeterMmm · Mar 13, 2010

Yes the initComponents method is read only to keep full control for the IDE. You may add yours in the constructor right after initComponents.

public class NewJFrame extends javax.swing.JFrame {

/** Creates new form NewJFrame */
public NewJFrame() {
    initComponents();
    myInitComponents();
}

public void myInitComponents() {
}