将 JMenuBar 添加到 JPanel?
我有一个JMenuBar和一个JPanel。我想将JMenuBar添加到JPanel中。我该怎么做?
我有一个JMenuBar和一个JPanel。我想将JMenuBar添加到JPanel中。我该怎么做?
您可以为JPanel使用BorderLayout,并将JMenuBar放入面板的NORTH区域
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(menubar, BorderLayout.NORTH);
JMenuBar是一个JComponent,可以像任何其他JComponent一样添加到容器中。
JMenuBar 使用 setJMenuBar 方法设置为 JFrame。
请参阅以下有关如何使用它们的教程。
http://download.oracle.com/javase/tutorial/uiswing/components/menu.html