用不同的渐变重新绘制摆动按钮 [英] repaint swing button with different gradient
本文介绍了用不同的渐变重新绘制摆动按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在单击时使用不同的渐变重新绘制 JButton.我已经覆盖了paintComponent(Graphics) 方法来进行初始绘制.Onclick 我想重新绘制它,但我不希望用户在 actionperformed 事件中这样做,因为我希望它成为一个独立的组件.
How can I repaint a JButton with a different gradient when it is clicked. I have overridden the paintComponent(Graphics) method to do the initial paint. Onclick I want to repaint it but I dont want the user to be doing this in the actionperformed event as I want this to be a standalone component.
关于如何实现这一点的任何想法.
Any ideas how this can be achieved.
谢谢
推荐答案
最简单的方法是使用 setPressedIcon()
,但你也可以覆盖paint()
在 ButtonUI
委托,如本示例所示.
The easiest approach is to use setPressedIcon()
, but you can also override paint()
in the ButtonUI
delegate, as shown in this example.
这篇关于用不同的渐变重新绘制摆动按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文