0

I'm trying to add an image to a button instead of text. I looked at some examples, and I can't figure out what I am missing.

I've imported this because the ex. had it. Don't know if it is needed.

import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.ImageIcon;

Then this is where I make the icon.

ImageIcon pauseIcon = createImageIcon("pause.bmp");
        
pause= new JButton("pause ", pauseIcon);

This is the error I get:
"cannot resolve symbol
symbol : method createImageIcon (java.lang.String)
location: class RAAN
ImageIcon pauseIcon = createImageIcon("pause.bmp");"
^


Thanks for helping

4
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by ProgrammersTalk
0

just create imageicon like this

Icon icon = new ImageIcon("fish20.gif");

and add it...in you button

JButton bstop = new JButton("STOP",icon);

0

Hi!
Try this piece of code :
ImageIcon image = new ImageIcon("ANYTHING.GIF");
If i'm not wrong you can add as image icon only GIF files, so try converting your bmp (you can find such programs on http://softpedia.com).
Hope it works.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.