This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 152770

Summary: GUI Builder should remove unused imports
Product: guibuilder Reporter: alexandros <alexandros>
Component: CodeAssignee: issues@guibuilder <issues>
Status: NEW ---    
Severity: blocker CC: adam_myatt, satory
Priority: P3    
Version: 6.x   
Hardware: All   
OS: All   
Issue Type: ENHANCEMENT Exception Reporter:

Description alexandros 2008-11-08 11:07:43 UTC
The GUI Builder should remove imports that are not used in the java.awt and javax.swing packages and subpackages.
Comment 1 alexandros 2008-11-08 11:11:50 UTC
--For instance:
--Before:
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class Main extends JFrame {

    /** Creates new form Main */
    public Main() {
        initComponents();
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new JScrollPane();
        jTextArea1 = new JTextArea();

        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        getContentPane().add(jScrollPane1, BorderLayout.CENTER);
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Main();
            }
        });
    }

    // Variables declaration - do not modify
    private JScrollPane jScrollPane1;
    private JTextArea jTextArea1;
    // End of variables declaration

}
--After:

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;

public class Main extends JFrame {

    /** Creates new form Main */
    public Main() {
        initComponents();
        setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new Main();
            }
        });
    }

    // Variables declaration - do not modify
    // End of variables declaration

}

--Unused imports should be removed:
----java.awt.BorderLayout
----import javax.swing.JScrollPane
----import javax.swing.JTextArea
Comment 2 Jiri Vagner 2008-11-10 08:22:02 UTC
Thank you for your report. Maybe it will be possible to remove automatically unused import of xyz component, while
removing that component. Also we could automatically remove unused beansbinding imports if its possible.
Comment 3 Tomas Pavek 2013-06-18 17:32:52 UTC
*** Bug 124244 has been marked as a duplicate of this bug. ***
Comment 4 Tomas Pavek 2013-06-18 17:36:14 UTC
Trying to "fix imports" might have sense when "Generate Full Classnames" option is off, in which case the GUI builder adds imports -- so could also remove them.
Comment 5 Tomas Pavek 2013-06-18 17:36:36 UTC
*** Bug 231161 has been marked as a duplicate of this bug. ***