views:

225

answers:

1

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 opacity 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 ?

A: 

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!)

chepseskaf