我如何将图标放入 jLabel
How do i put a icon to jLabel
默认情况下,它有一个路径为 /img/profileicon/29.png
的图像
但后来从主要我想改变它,但由于某种原因而不是改变它消失了。
代码:
int iconId = summoner.getProfileIconId();
ImageIcon img = new javax.swing.ImageIcon("/img/profileicon/"+iconId+".png");
profileIconImg.setIcon(img);
最后我能够使用这段代码,利用 class.getResource
URL iconUrl = EuwGG.class.getResource("/img/profileicon/"+profileIconId+".png");
Image profileImage = ImageIO.read(iconUrl);
ImageIcon profileIcon = new ImageIcon(profileImage);
Image i = profileIcon.getImage().getScaledInstance(125, 125, Image.SCALE_SMOOTH);
profileIcon = new ImageIcon(i);
profileIconImg.setIcon(profileIcon);
默认情况下,它有一个路径为 /img/profileicon/29.png
的图像
但后来从主要我想改变它,但由于某种原因而不是改变它消失了。
代码:
int iconId = summoner.getProfileIconId();
ImageIcon img = new javax.swing.ImageIcon("/img/profileicon/"+iconId+".png");
profileIconImg.setIcon(img);
最后我能够使用这段代码,利用 class.getResource
URL iconUrl = EuwGG.class.getResource("/img/profileicon/"+profileIconId+".png");
Image profileImage = ImageIO.read(iconUrl);
ImageIcon profileIcon = new ImageIcon(profileImage);
Image i = profileIcon.getImage().getScaledInstance(125, 125, Image.SCALE_SMOOTH);
profileIcon = new ImageIcon(i);
profileIconImg.setIcon(profileIcon);