Changing image on JButton when mouse is over it

B

Brian

Hi all

I'm trying to get a JButton to change the image when the mouse is over
it, but I can't get it to work.

The code:

ImageIcon icon = new ImageIcon("images/MRButton.png"");
JButton MRButton = new JButton(icon);

button.addMouseListener(new MouseListener(){

public void mouseEntered(MouseEvent arg0) {
//I have tried this - but i don't work :(
icon = new ImageIcon("lommeregner/images/MRButton_over.png");
}

public void mouseExited(MouseEvent arg0) {
//some code here ...
}

}

Can someone give me a hint to solve this little problem ?

/Brian
 
S

SadRed

Hi all

I'm trying to get a JButton to change the image when the mouse is over
it, but I can't get it to work.

The code:

ImageIcon icon = new ImageIcon("images/MRButton.png"");
JButton MRButton = new JButton(icon);

button.addMouseListener(new MouseListener(){

public void mouseEntered(MouseEvent arg0) {
//I have tried this - but i don't work :(
icon = new ImageIcon("lommeregner/images/MRButton_over.png");

}

public void mouseExited(MouseEvent arg0) {
//some code here ...

}
}

Can someone give me a hint to solve this little problem ?

/Brian

setRolloverIcon()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top