add JMenuBar to a JPanel?
问题 I've got a JMenuBar and a JPanel. I'd like to add the JMenuBar to the JPanel. How would I do so? 回答1: 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. 回答2: JMenuBars are set to the JFrame using the setJMenuBar method. See the following tutorial on how to use them.