为什么菜单不显示图标? 你的JMenuItem根本就没有加上你的ICON 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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); }} 只有Icon对象,却没有使用。open.setIcon(a) ImageIcon image1 = new ImageIcon(Menu1.class.getResource("aa.png"));//aa.png为图形文件open.setIcon(image1); 各位乡绅贵人RomandAccessFile(goodghost)给出的代码也不能显示图标。我绝对确认图标文件的存在,并路径和名称正确。 建议你换一个图片试试,如用一个jpg后缀的文件尝试一下! Sorry忘了告诉你了,,Java只支持JPG.GIF.PNG的文件,在我的网站上有一个将Ico转换为GIF或PNG的软件,Http://goodghost.com :)RomandAccessFile(goodghost)说的完全对。其实问题我已经解决,正想将经验发布的时候你已回答了。但我还是非常高兴看到你负责任的回答。 哪个大哥有jsp开发的”小区物业管理系统的源代码”,高分求 急求 公园租车 思路或 代码 解析URL地址的问题 获取宽度的函数是什么 回复韩国朋友的帖子! applet的问题,请执教!!各位大虾帮忙!! 关于JBuilder和Sun Java!!! 请问怎么设置组件上文字的字体? 请问什么是函数的超载模式? 关于对代码块一起抛异常的 快捷键是什么? 获得数据库里的所有数据库名? 发几篇swing中关于JTable中的运用-5
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);
}
}
open.setIcon(image1);
我绝对确认图标文件的存在,并路径和名称正确。
Java只支持JPG.GIF.PNG的文件,
在我的网站上有一个将Ico转换为GIF或PNG的软件,
Http://goodghost.com
RomandAccessFile(goodghost)说的完全对。
其实问题我已经解决,正想将经验发布的时候你已回答了。但我还是非常高兴看到你负责任的回答。