开发者

How set a translucid background color on jtextfield?

I have a snippet that change the color of a JTextField :

textField.setBackground(new Color(155, 0, 0, 155));

When the color is changing, the component has a strange behaviour: the cursor twinkling becomes not regular, as so the color op开发者_如何学编程acity that seems to change on ongoing repaint events. If the color is created without specifying alpha parameter, the bug seems to disappear.

Any ideas about how to use tranlucid color in JTextField ?


I read an article on Sun's site: Unleash Your Creativity with Swing and the Java 2D API!

[...]The third translucent painting technique is the most powerful, allowing for arbitrary painting to be done translucently. By invoking setComposite on a Graphics2D object with an instance of java.awt.AlphaComposite, you can specify a translucency level to be used in subsequent paint calls.[...]"

I've tried to use this technique in paintComponent context and I succeeded to use an translucid color. (RTFM... I knew it!)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜