我如何淡出摆动的图像? [英] How do I fade an image in swing?

查看:152
本文介绍了我如何淡出摆动的图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类从继承的JPanel与它的形象,我想成立一​​个小动画显示面板/图像,然后消失它当一个事件触发。

I've got class which inherits from JPanel with an image on it and i want to set up a little animation to display the panel/image and then fade it out when an event fires.

我presumably建立一个线程,断火的动画,但我怎么做实际上做的褪色?

I presumably set up a thread and fire off the animation but how do I do actually do the fade?

推荐答案

您可以做自己的线程,但它可能是更容易使用的三叉戟库来处理它。如果你创建你的类的setter被调用(比如 setOpacity ),你可以问三叉戟超过一个特定的时间段,从1.0的不透明度字段插值到0.0(这里的如何使用三叉戟)的一些文档的的。

You can do the threading yourself, but it might be easier to use the Trident library to handle it. If you create a setter on your class called (say, setOpacity), you can ask trident to interpolate the "opacity" field from 1.0 to 0.0 over a specific period of time (here's some of the docs on how to use Trident).

当你画的图像,你可以做的透明度的AlphaComposite ,使用复合材料的阿尔法参数更新的不透明度的价值。有一个太阳教程,包括阿尔法复合例如

When you're painting the image, you can do the transparency with an AlphaComposite, using the updated "opacity" value for the composite's alpha parameter. There is a Sun tutorial that includes an alpha composite example.

这篇关于我如何淡出摆动的图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆