You can use a BorderLayout for your JPanel and put the JMenuBar into the NORTH area of the panel with
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(menubar, BorderLayout.NORTH);
JMenuBar is a JComponent and can be added to a Container like any other JComponent.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…