当前页面: 开发资料首页 → J2SE 专题 → 请问如何在java的菜单项上添加图标~~!!
请问如何在java的菜单项上添加图标~~!!
摘要: 请问如何在java的菜单项上添加图标~~!!
如题~!
参考 JMenuItem 的JDK文档
public JMenuItem(String text, Icon icon)
Creates a JMenuItem with the specified text and icon.
Parameters:
text - the text of the JMenuItem
icon - the icon of the JMenuItem
其中icon是实现了Icon接口的某个类,可以使用ImageIcon这个类。参考它的JDK文档,用这个构造函数创建一个ImageIcon对象:
ImageIcon(String filename)
Creates an ImageIcon from the specified file.
接下来的这一步并不是一定需要的,但是没有调试过,我也不是很确定
将 ImageIcon 对象Wrap到一个 IconUIResource 对象
IconUIResource(Icon delegate)
Creates a UIResource icon object which wraps an existing Icon instance.
然后将 IconUIResource 对象作为参数传递给JMenuItem的构造函数
换一句话说,直接用 ImageIcon 对象构造 JMenuItem 行得通的话,就不需要使用IconUIResource参数了。
谢谢了 问题解决
不客气,互勉