esanits
esanits

Reputation: 197

JLabel over transparent painted Rectangle?

I set the background of a JWindow completely transparent. Then I painted a rounded Rectangle (RGB: 0,0,0,100) in it's paint-Method and added a JLabel to the JWindows ContentPane. But when I try to repaint the JWindow to update the JLabel, it doesn't remove the old Rectangle and the old value of the JLabel. So the result is that my custom tooltip box (what it should be) gets less transparent and you cannot read the JLabels contents, because it overlays the old contens.

Is there any way to solve this problem?

BTW, if I don't repaint, it doesn't get less transparent, but the new contents of my JLabel overlays the old Contents, like it is, when I repaint.

Upvotes: 1

Views: 630

Answers (1)

z7sg Ѫ
z7sg Ѫ

Reputation: 3203

First you should override paintComponent instead of paint and call super.paintComponent(g). You should leave JWindow opaque, because the component on the rearmost layer will clear the old contents. If all the layers are transparent you will end up with screen garbage.

See painting with Swing. Perhaps you really wanted to create translucent windows?

Upvotes: 1

Related Questions