我有一个Java应用程序,我希望它有一个带图标的RibbonApplicationMenu。
我已经有了RibbonApplicationMenu但没有图标。我想知道是否可以在RibbonApplicationMenu中添加一个Icon?
我还发现了以下代码,每次使用下面的代码时,它都会给我异常
public static ResizableIcon getResizableIconFromResource(String resource){
return ImageWrapperResizableIcon.getIcon(MainFrame.class.getClassLoader().getResource(resource), new Dimension(48, 48));
}
例外:
线程“AWT-EventQueue-0”中的异常java.lang.NullPointerException at org.pushingpixels.flamingo.api.common.icon.ImageWrapperResizableIcon.getIcon(ImageWrapperResizableIcon.java:71) 在com.scamex.app.MainFrame.getResizableIconFromResource(MainFrame.java:187) 在com.scamex.app.MainFrame $ 1.run(MainFrame.java:86) at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251) at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705) at java.awt.EventQueue.access $ 000(EventQueue.java:101) at java.awt.EventQueue $ 3.run(EventQueue.java:666) at java.awt.EventQueue $ 3.run(EventQueue.java:664) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76) 在java.awt.EventQueue.dispatchEvent(EventQueue.java:675) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105) 在java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
答案 0 :(得分:0)
JCommandButton button1 = new JCommandButton("Square", getResizableIconFromResource("48px-Crystal_Clear_action_bookmark.png"));
public static ResizableIcon getResizableIconFromResource(String resource)
{
System.out.println("Resources:"+resource);
return ImageWrapperResizableIcon.getIcon(MainFrame.class.getClassLoader().getResource("resources/"+resource), new Dimension(48, 48));
}
答案 1 :(得分:0)
这是由于错误的图像路径所导致的,因此为NULL。尝试使用正确的图像路径,它将起作用。