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

Recommended Answers

All 3 Replies

just create imageicon like this

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

and add it...in you button

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

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.

make sure you have your image with your current .java file

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.