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 75292

Summary: Incorrect code generated when JMenuBar added to JPanel
Product: guibuilder Reporter: kitfox <kitfox>
Component: CodeAssignee: issues@guibuilder <issues>
Status: RESOLVED DUPLICATE    
Severity: blocker    
Priority: P3    
Version: 5.x   
Hardware: All   
OS: Windows XP   
Issue Type: ENHANCEMENT Exception Reporter:

Description kitfox 2006-04-20 16:06:45 UTC
When a JMenuBar is added to a JPanel, at the moment, it is simply added to the
Other Components section in the navigator.  Instead, it should be added as a
regular Component and appear in the layout area of the panel.  

The below code demonstrates how a JMenuBar can be added to a JPanel.


public class TestMenuFrame extends javax.swing.JFrame
{
    class InnerPanel extends JPanel
    {
        InnerPanel()
        {
            setLayout(new BorderLayout());
            
            JMenuBar menuBar =  new JMenuBar();
            JMenu favs = new JMenu("Menu");
            menuBar.add(favs);   //this line missing
            favs.add(new JMenuItem("Alpha"));
            add(menuBar, BorderLayout.NORTH);
        }
    }
    
    InnerPanel innerPanel = new InnerPanel();
    
    /** Creates new form TestMenuFrame */
    public TestMenuFrame()
    {
        initComponents();
        
        this.getContentPane().add(innerPanel, BorderLayout.CENTER);
        
        setSize(640, 480);
    }
    
    /** 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(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        pack();
    }// </editor-fold>
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
            public void run()
            {
                new TestMenuFrame().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify
    // End of variables declaration
    
}
Comment 1 Jiri Prox 2006-04-24 12:12:02 UTC
reassigning to form for evaluation
Comment 2 Tomas Pavek 2012-09-11 16:06:30 UTC

*** This bug has been marked as a duplicate of bug 14785 ***