Reputation: 68
I'd like to change the appearance of a button when it's in pressed/clicked/selected state.
To be more specific, I'd like to change it's border to BorderFactory.createLoweredBevelBorder()
when it' is pressed/clicked/selected.
How can I do this?
Upvotes: 2
Views: 4249
Reputation: 109823
Have look at ButtonModel for JButtons JComponents, there are implemented all your requierements
Upvotes: 2
Reputation: 32391
Please see the code below. It sets the border when pressed and resets it when released. You can also do this on mouseEntered
/ mouseExited
.
button.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
button.setBorder(BorderFactory.createLoweredBevelBorder());
}
public void mouseReleased(MouseEvent e) {
button.setBorder(null);
}
});
Upvotes: 3