How to put images on buttons?

I am currently working a project and need to mount an image onto a button, so when the image is clicked on it makes the button event work?
[145 byte] By [lozengera] at [2007-11-26 17:41:10]
# 1
Are you talking about setIcon()?
zadoka at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 2
Assuming that the image is represented by an ImageIcon instance say imageicon this is how it's done.JButton jbutton=new JButton(imageicon);
qUesT_foR_knOwLeDgea at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 3
[url http://java.sun.com/j2se/1.5.0/docs/api/index.html]setIcon[/url]
abillconsla at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 4
Icon image = new ImageIcon("Your Image's path here");JButton imageButton = new JButton(image);
CaptainMorgan08a at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 5
set icons? , do i have to have the image in the same folder as where the code is saved? I have not been able to find any code showing how to apply images onto buttons on a GUI.
lozengera at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 6
> I am currently working a project and need to mount an> image onto a button, >so when the image is clicked on> it makes the button event work?Actually you are clicking the button not the image.The image is just embedded on top of the button.
qUesT_foR_knOwLeDgea at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 7

> set icons? , do i have to have the image in the same

> folder as where the code is saved? I have not been

> able to find any code showing how to apply images

> onto buttons on a GUI.

Look at the tutorials:

http://java.sun.com/docs/books/tutorial/uiswing/components/button.html

zadoka at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 8
> do i have to have the image in the same> folder as where the code is saved?No, you could provide the entire path of the Image.
CaptainMorgan08a at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 9

> set icons? , do i have to have the image in the same

> folder as where the code is saved? I have not been

> able to find any code showing how to apply images

> onto buttons on a GUI.

Did you atleast read reply 2 and 4?Have you ever read the JButton API?There's no necessity that the image has to be in the same folder.You use have to specify the absolute path of the image when you create an instance representing it.

qUesT_foR_knOwLeDgea at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 10
Thank you for your help, i read the API yet i did not understand.
lozengera at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...
# 11
> Thank you for your help, i read the API yet i did not> understand.If you have made an attempt it's always appreciated.Infact it helps you to understand in a better way.
qUesT_foR_knOwLeDgea at 2007-7-9 0:09:21 > top of Java-index,Java Essentials,New To Java...