Making Image button look pressed/clicked in Swing

时光怂恿深爱的人放手 提交于 2020-01-13 08:24:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!