Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove auto generated code from Netbeans

Whenever I create new JPanelForm, NetBeans will create some auto generated code in initComponents() method. How can I remove this auto generated code from my JPanelForm ?

like image 379
Neo Avatar asked Sep 24 '26 20:09

Neo


2 Answers

Using a GUI designer like Netbeans or Eclipse, will force you to accept certain conventions. One of these conventions is the automatic generation of initComponents() method by Netbeans.

Although Netbeans is highly configurable and allows the user to modify lots of things, the initComponents() method is always used by the GUI builder.

When you create a JPanel Form in Netbeans this is the initComponents() you get by default:

private void initComponents() {

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 400, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 300, Short.MAX_VALUE)
    );
}

If you take a close look at it you will see it has only layout instructions. You may want to change the layout. Let's say you want to have a BorderLayout for your JPanel. Go to the Navigator, change the layout by choosing the right property and this is your new initComponents() now:

private void initComponents() {

    setLayout(new java.awt.BorderLayout());
}

If someone is in a Swing learning phase, it is wiser to avoid using a GUI Builder. Designing the components by hand will give a better understanding of how things work. The GUI builder will always be there to automate procedures once the principles of Swing have become familiar.

like image 91
Costis Aivalis Avatar answered Sep 27 '26 10:09

Costis Aivalis


The Problem is that for a class XYZ with generated code there is a file XYZ.form (Same folder as the XYZ.java file). Netbeans unfortunately hides this file in it's Files / Projects Views, so you have to remove it by other means. After the .form file is removed the design tab for this class should disappear in Netbeans and you can delete the auto-generated code.

like image 28
fabian Avatar answered Sep 27 '26 09:09

fabian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!