[英]Why aren't my menu drop downs names not showing Java
I'm doing a program where I'm working with getting the menu's to appear, but for some reason I can't seem to get the names for my menu drop downs to appear.I would greartly appreciante some help with this matter. 我正在做一个程序以显示菜单,但由于某种原因,我似乎无法使菜单下拉菜单的名称出现。我将在此方面提供一些帮助。
public class Application extends JPanel implements ActionListener{
JPanel p;
JFrame f;
JMenu m;
JMenu m2;
JMenuBar menu;
JMenuItem item;
JMenuItem item2;
Application()
{
super();
//creating panel
f=new JFrame("CMPSC 221 Exam 2 ");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setSize(200,200);
f.setContentPane(new JDesktopPane());
m2 = new JMenu();
menu = new JMenuBar();
m = new JMenu();
//adding the the drop down menu
m.setName("File");
m.add("New");
m.addSeparator();
m.add("Open");
menu.add(m);
m2.setName("Edit");
m2.add("Copy");
m2.addSeparator();
m2.add("Paste");
menu.add(m2);
menu.setVisible(true);
f.setJMenuBar(menu);
f.setVisible(true);
}
不要使用m.setName
将名称传递给JMenu()
构造函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.