用不同的渐变重新绘制秋千按钮 [英] 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() /download.oracle.com/javase/6/docs/api/javax/swing/plaf/ButtonUI.html\"rel =nofollow noreferrer> ButtonUI
代表,如示例所示。
The easiest approach is to use setPressedIcon()
, but you can also override paint()
in the ButtonUI
delegate, as shown in this example.
这篇关于用不同的渐变重新绘制秋千按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!