How to delete automatically generated code from NetBeans

Whenever I create a new jpanelform, NetBeans creates some automatically generated code in the initcomponents () method How do I remove this automatically generated code from jpanelform?

Solution

Using GUI designers like NetBeans or eclipse forces you to accept certain conventions One of the conventions is that NetBeans automatically generates the initcomponents () method

Although NetBeans is highly configurable and allows users to modify a large amount of content, the GUI builder always uses the initcomponents () method

When creating a JPanel form in NetBeans, this is initcomponents () obtained 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 look at it carefully, you will find that it has only layout instructions You may want to change the layout Suppose you want to set up a borderlayout for your JPanel Go to the navigator and change the layout by selecting the correct properties. This is your new initcomponents ():

private void initComponents() {

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

If someone is in the swing learning phase, it would be wiser to avoid using GUI builder Designing components manually provides a better understanding of how they work Once swing's principles become familiar, the GUI builder will always be there to automate the program

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>