Reputation: 5
I have a music player application that has a repeat button. I want to make it so when the user hovers over the repeat button with their cursor, the text will change to display the current state of the repeat option (off, one, or list). How can I program my button to do this?
Upvotes: 0
Views: 168
Reputation: 3534
Use a MouseListener
and the methodes mouseEntered()
and mouseExited()
.
final JButton btn = new JButton("repeat");
btn.addMouseListener(new MouseAdapter() {
@Override
public void mouseEntered(MouseEvent e) {
btn.setText("hover");
}
@Override
public void mouseExited(MouseEvent e) {
btn.setText("repeat");
}
});
Upvotes: 2