Rob Camick wrote:Swing doesn't know how to paint components with transparency correctly.
Swing expects the component to be:
1. opaque - in which case it doesn't paint the parent component and you get painting artifacts because the background is not cleared before the child component is painted, or
2. transparent, in which case the parent component is painted, but the background of the child component is not painted, which means you manually need to paint the background.
For a reusable solution check out Backgrounds With Transparency.
You would use it in your code as follows:
Rob Camick wrote:
with a foreground on the label that has its transparency set.
The foreground has nothing to do with this problem.
The foreground is used for setting the color of the text. There is no text to display so setting that property does nothing.
Stephan van Hulst wrote:Why are you calling setOpaque(true) when clearly you want the component to be transparent?
setOpaque(true) tells Swing that the container underneath the opaque component doesn't need to draw its content, because the component already draws every pixel that it occupies. I don't know if that is the source of your problems, but it could definitely be a reason why the container underneath the label appears white.
I find the way you're trying to do this very iffy. Can you explain your use case a bit better, maybe we ca suggest a better method of doing things.
Tim Holloway wrote:Don't keep the File Chooser as an instance variable. Obtain it when needed, then discard it.
Also, keep your data (serializable - Model) classes separate from your UI classes. The classes that construct and use the GUI (View, Controller) should not be serialized.
Campbell Ritchie wrote:Don't extend JFrame. Your application ISN'T‑A JFrame; it HAS‑A JFrame.
Rob Spoor wrote:A must-watch when using GridBagLayout/GridBagConstraints: