Reputation: 139
I have a JFrame that holds a JPanel. I want to make the frame completely transparent and the panel slightly transparent.
I'm using the following code to do so:
frame.setBackground(new Color(0, 0, 0, 0));
panel.setBackground(new Color(51, 51, 51, 190));
The desired effect is achieved, however, when I make the JFrame transparent using this method it distorts all of the other components.
The following image demonstrates this better than I can explain.
On the left is an example with no transparency and the text appears clearly. On the right the panel and the frame are set using the code above, and the text is distorted.
What am I missing?
Upvotes: 1
Views: 163
Reputation: 324088
however, when I make the JFrame transparent using this method it distorts all of the other components.
The problem is Swing thinks the component is opaque so it doesn't paint the background first so you get painting artifacts.
Check out Background With Transparency. It has two simple solutions:
Upvotes: 2