To prevent spam users, you can only post on this forum after registration, which is by invitation. If you want to post on the forum, please send me a mail (h DOT m DOT w DOT verbeek AT tue DOT nl) and I'll send you an invitation in return for an account.

How to use an image on a button

jaclaesjaclaes Posts: 6
edited September 2011 in - Development
Hi

I would like to create a button with only an icon on it. I've made icons and have put them in the folder of my java files. But how can I use it on buttons? 

This is my code
        JButton b = newButton(new ImageIcon("up.jpg"),"move down");
...
protected JButton newButton(ImageIcon icon, String tooltip) {
JButton b = new SlickerButton(icon);
b.setToolTipText(tooltip);
b.setForeground(new Color(40, 40, 40));
return b;
}
There is no error (not at compile time, not at runtime), but I get an empty button. 

I've also tried different paths to the image, but with no success
- /LogMerge/src/org/processmining/plugins/logmerge/rulebasedmerger/up.jpg
LogMerge/src/org/processmining/plugins/logmerge/rulebasedmerger/up.jpg
- src/org/processmining/plugins/logmerge/rulebasedmerger/up.jpg
- logmerge/rulebasedmerger/up.jpg
- rulebasedmerger/up.jpg
- up.jpg

I've also tried the same stuff with JButton instead of SlickerButton, but with no success.

Any suggestions?

Jan Claes
Ghent University, Belgium

Tagged:
Sign In or Register to comment.