将JMenuBar添加到JPanel? [英] add JMenuBar to a JPanel?
本文介绍了将JMenuBar添加到JPanel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个JMenuBar和一个JPanel。我想将JMenuBar添加到JPanel。我该怎么做?
I've got a JMenuBar and a JPanel. I'd like to add the JMenuBar to the JPanel. How would I do so?
推荐答案
你可以使用 BorderLayout ,并使用
JPanel p = new JPanel();
p.setLayout(new BorderLayout());
p.add(menubar, BorderLayout.NORTH);
JMenuBar是一个JComponent,可以像任何其他JComponent一样添加到Container中。
JMenuBar is a JComponent and can be added to a Container like any other JComponent.
这篇关于将JMenuBar添加到JPanel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文