Here you can find the source of setImageIcon(JButton b, String fileName, String tip)
public static void setImageIcon(JButton b, String fileName, String tip)
//package com.java2s; //License from project: Apache License import java.awt.Dimension; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JButton; public class Main { public static void setImageIcon(JButton b, String fileName, String tip) { ImageIcon i = null;/*from w w w . ja v a 2 s.com*/ URL u = ClassLoader.getSystemResource("img/" + fileName); i = new ImageIcon(u); b.setIcon(i); b.setPreferredSize(new Dimension(61, 81)); b.setToolTipText(tip); b.setVerticalTextPosition(JButton.BOTTOM); b.setHorizontalTextPosition(JButton.CENTER); b.setText(tip); } }