java按钮图片设置 10
toolbar_main=newjavax.swing.JToolBar();bt_back=newjavax.swing.JButton(newImageIcon(th...
toolbar_main = new javax.swing.JToolBar();
bt_back = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/back.jpg")));
bt_forward = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/forward.jpg")));
bt_stop = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/stop.jpg")));
bt_refresh = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/refresh.jpg")));
bt_home = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/home.jpg")));
显示这段代码出错·····
错误是
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at JWebBrowser.initComponents(JWebBrowser.java:51)
at JWebBrowser.<init>(JWebBrowser.java:35)
at JWebBrowser$5.run(JWebBrowser.java:367)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source) 展开
bt_back = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/back.jpg")));
bt_forward = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/forward.jpg")));
bt_stop = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/stop.jpg")));
bt_refresh = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/refresh.jpg")));
bt_home = new javax.swing.JButton(new ImageIcon(this.getClass().getClassLoader().getResource("/home.jpg")));
显示这段代码出错·····
错误是
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at JWebBrowser.initComponents(JWebBrowser.java:51)
at JWebBrowser.<init>(JWebBrowser.java:35)
at JWebBrowser$5.run(JWebBrowser.java:367)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source) 展开
2013-05-16
展开全部
找不到图片文件,和.class文件包的ROOT中,没找到对应的图片文件
略作简化
bt_back = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/back.jpg")));
bt_forward = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/forward.jpg")));
bt_stop = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/stop.jpg")));
bt_refresh = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/refresh.jpg")));
bt_home = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/home.jpg")));
略作简化
bt_back = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/back.jpg")));
bt_forward = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/forward.jpg")));
bt_stop = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/stop.jpg")));
bt_refresh = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/refresh.jpg")));
bt_home = new javax.swing.JButton(new ImageIcon(this.getClass().getResource("/home.jpg")));
追问
怎么解决呢·?!怎么会找不到图片··图片就在根目录下··
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
图片路径是否写对
bt_home = new javax.swing.JButton(new ImageIcon("image\\00.jpg"));
bt_home = new javax.swing.JButton(Toolkit.getDefaultToolkit().getImage("image\\123.jpg"));
bt_home = new javax.swing.JButton(new ImageIcon("image\\00.jpg"));
bt_home = new javax.swing.JButton(Toolkit.getDefaultToolkit().getImage("image\\123.jpg"));
追问
路径是对的···图片就放在根目录下···
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
swing不能这样设置图片,需要重写jbutton里的drawComponent方法
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询