This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center




7年前关闭。





我从Netbeans中的资源添加图像图标,但在运行按钮为空
从Netbeans->选择按钮->属性->图标->添加图像->项目中的图像。我选择了程序包和图像,将其添加,然后在Netbeans中的JButton中可视化图像,但是当我运行项目JButton为空时。

从ide生成的代码:

jbtnApriDaFile = new javax.swing.JButton();
jbtnApriDaFile.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/html5.png"))); // NOI18N
add(jbtnApriDaFile, new org.netbeans.lib.awtextra.AbsoluteConstraints(500, 10, 30, 30));

最佳答案

删除路径中的第一个/

另外,在jbtnApriDaFile.setIcon ()之后,尝试调用jbtnApriDaFile.revalidate ()

10-07 13:19
查看更多