Java examples for 2D Graphics:Icon
set Button Icon
//package com.java2s; import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.io.File; import java.io.IOException; public class Main { public static void setButtonIcon(JButton btn, String iconPath) { Image icon;// ww w . j a va 2 s .co m try { icon = ImageIO.read(new File(iconPath)); Image scaled = icon.getScaledInstance(15, 15, Image.SCALE_SMOOTH); btn.setIcon(new ImageIcon(scaled)); } catch (IOException e) { e.printStackTrace(); } } }