问题
I created a JButton which has an image set as an icon representing the button. Now, I've set
setContentAreaFilled(false);
setBorderPainted(false);
setOpaque(false);
the properties which this makes an image-button look nice with no borders or background colors etc.
Now the problem is that when I click on the image, it shows no onclick effects of a button, so when there is some background processing involved or some event is bring fired on click of button which takes time to process the request and return something, it gives an impression that the button was not clicked and the user might keep clicking it.
How do I make a button which has an icon set with the above mentioned properties and yet I have some control over setting the onpress or onmouseover events.
回答1:
I found the answer: setRolloverIcon() and setPressedIcon() will do the magic.
来源:https://stackoverflow.com/questions/11351728/making-image-button-look-pressed-clicked-in-swing