【发布时间】:2022-01-08 09:54:09
【问题描述】:
我看不到带有这些代码行的图标,尽管它应该可以工作。 代码如下:
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class IconOfDialog {
public static void main(String[] args) {
ImageIcon orignalIcon = new ImageIcon("/Images/icons8-ok-100.png");
Image iconImage = orignalIcon.getImage().getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH);
ImageIcon okIcon = new ImageIcon(iconImage);
JOptionPane.showConfirmDialog(null, "Successfully connect to the database",
"Successful Connection", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, okIcon);
}
}
结果无一例外:
【问题讨论】:
-
简单来说...图片文件找不到,路径错误,文件名错误,或者损坏。您的图像所在的目录实际上是命名为
Images还是命名为images(全部小写)。尝试使用图像的实际完整路径,看看是否有效。如果找不到文件,new ImageIcon("somefile")不会抛出异常,它只是返回 null。 Give this SO Post a thorough read
标签: java image swing joptionpane imageicon