开发者

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开发者_JAVA百科 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.


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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜