你的JMenuItem根本就没有加上你的ICON

解决方案 »

  1.   

    import javax.swing.*;
    import java.awt.event.*;public class Menu1{
    public static void main(String[] args){
    Icon a=new ImageIcon("d:/java/image/add.ico");
    JMenuItem open=new JMenuItem("Open",KeyEvent.VK_O);
    open.setIcon(a);//就是这一行
    JMenu fileMenu=new JMenu("File");
    fileMenu.add(open);
    JMenuBar mb=new JMenuBar();
    mb.add(fileMenu);
    JFrame f=new JFrame();
    f.setJMenuBar(mb);
    f.addWindowListener(new WindowAdapter(){
    public void windowClosing(WindowEvent e){
    System.exit(0);
    }
    });
    f.setBounds(100,100,100,100);
    f.setVisible(true);
    }
    }
      

  2.   

    只有Icon对象,却没有使用。open.setIcon(a)
      

  3.   

    ImageIcon image1 = new ImageIcon(Menu1.class.getResource("aa.png"));//aa.png为图形文件
    open.setIcon(image1);
      

  4.   

    各位乡绅贵人RomandAccessFile(goodghost)给出的代码也不能显示图标。
    我绝对确认图标文件的存在,并路径和名称正确。
      

  5.   

    建议你换一个图片试试,如用一个jpg后缀的文件尝试一下!
      

  6.   

    Sorry忘了告诉你了,,
    Java只支持JPG.GIF.PNG的文件,
    在我的网站上有一个将Ico转换为GIF或PNG的软件,
    Http://goodghost.com
      

  7.   

    :)
    RomandAccessFile(goodghost)说的完全对。
    其实问题我已经解决,正想将经验发布的时候你已回答了。但我还是非常高兴看到你负责任的回答。