Java JButton setImageIcon(JButton b, String fileName, String tip)

Here you can find the source of setImageIcon(JButton b, String fileName, String tip)

Description

set Image Icon

License

Apache License

Declaration

public static void setImageIcon(JButton b, String fileName, String tip) 

Method Source Code

//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);
    }
}

Related

  1. renderImageOnly(JButton button)
  2. setButtonNo(JButton anButton)
  3. setCancelButton(final JRootPane rp, final JButton b)
  4. setEmptyBorder(JButton button, int paddingTop, int paddingLeft, int paddingBottom, int paddingRight)
  5. setEnable(boolean b, JButton... bs)
  6. setMacBevelButton(JButton button)
  7. setTransparent(JButton btn)
  8. setupAutoRepeat(final JButton button, final int intervalMs)
  9. setWFActionMap(Vector actionButtons, String action, Map wfActionMap)