I am creating an image button class using JLabel and it's setIcon() method. It also has a MouseListener, so that when the mouse goes over the button, the image changes colour.
I had it working nicely on my PC, buy when I uploaded my applet and tried it, no image would be displayed on m0useover...
It now displays no images at all regardles of where the mouse is. The code is quite simple, but I can't work out what is missing or what might be wrong. Does anyone have any ideas?...
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
you've overridden paintComponent() and commented out the super line public void paintComponent(Graphics g) { //super.paintComponent(g);
It worked OK for me (uncommenting above). I also changed the name from Button, to avoid any conflicts with java.awt.Button.
only problem was the text displayed over the icon, so I passed "" as the text in the constructor, and the icons toggled between #1 and #2, depending on mouse position
James Hodgkiss
Ranch Hand
Joined: Jan 22, 2004
Posts: 401
posted
0
Cheers Michael,
Meant to comment out the entire paintComponent method... late night.
I've found the source of the problem now. The filenames of the images I were using were 'yellowButton.jpg' and 'blueButton.JPG' . My code had used 'yellowButton.jpg' and 'blueButton.jpg' . The JPG / jpg difference was the reason it wasn't working when my applet was on the server, despite the image not coming up as null and despite the applet working when it was local on my machine...
Anyhow, thanks for checking the code out for me and your help. Much appreciated.
Cheers, James
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.