我在编写记事本程序时加入了文件选择窗口和鼠标右键菜单,可是把文件选择JFileChoose加到面板当中,后加入右键菜单的话就无法显示右键菜单,先把右键菜单加进去的话,可以打开文件选择窗口,但是选择文件之后文本框内没有显示,调试的时候确定内容已经加入到JTextarea中
public MynotePad ()
{
textmenu=new JTextAreaMenu();
jp=new JPanel();
jta=new JTextArea();
jsp=new JScrollPane(jta);
jmb=new JMenuBar();
jm1=new JMenu("文件(F)");
jm1.setMnemonic(*F*);
//添加并注册菜单栏
jmi1=new JMenuItem("打开");
jmi1.addActionListener(this);
jmi1.setActionCommand("open");
jmi2=new JMenuItem("保存");
jmi2.addActionListener(this);
jmi2.setActionCommand("save");
jmb.add(jm1);
jm1.add(jmi1);
jm1.add(jmi2);
this.setJMenuBar(jmb);
this.add(jsp);
this.add(textmenu);.........................这个和上一行的顺序,感觉一个把另一个覆盖了
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400,300);
this.setVisible(true);
}
public MynotePad ()
{
textmenu=new JTextAreaMenu();
jp=new JPanel();
jta=new JTextArea();
jsp=new JScrollPane(jta);
jmb=new JMenuBar();
jm1=new JMenu("文件(F)");
jm1.setMnemonic(*F*);
//添加并注册菜单栏
jmi1=new JMenuItem("打开");
jmi1.addActionListener(this);
jmi1.setActionCommand("open");
jmi2=new JMenuItem("保存");
jmi2.addActionListener(this);
jmi2.setActionCommand("save");
jmb.add(jm1);
jm1.add(jmi1);
jm1.add(jmi2);
this.setJMenuBar(jmb);
this.add(jsp);
this.add(textmenu);.........................这个和上一行的顺序,感觉一个把另一个覆盖了
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(400,300);
this.setVisible(true);
}