先把知识放在这,在整理,
public void setIcon(String file, JButton iconButton) {
ImageIcon icon = new ImageIcon(file);
Image temp = icon.getImage().getScaledInstance(iconButton.getWidth(),
iconButton.getHeight(), icon.getImage().SCALE_DEFAULT);
icon = new ImageIcon(temp);
iconButton.setIcon(icon);
}
java.net.URL imgURL = Frame.class.getResource("111.gif");
ImageIcon image =new ImageIcon(imgURL);
本文介绍了一种在Java中为按钮设置图标的实用方法。通过使用ImageIcon类,并结合按钮的尺寸调整图片大小,确保图标能适应不同的显示需求。此外,还展示了如何从类路径加载图像资源。
171万+

被折叠的 条评论
为什么被折叠?



