JDK-6687960 : Background of component invisible with Nimbus
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1,6u10
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2008-04-14
  • Updated: 2011-03-01
  • Resolved: 2008-06-09
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6
6u10 b26Fixed
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
1.6.0_10

ADDITIONAL OS VERSION INFORMATION :
ver XP

A DESCRIPTION OF THE PROBLEM :
When I have e.g. a JEditorPane on a JPanel and set:
myEditorPane.setOpaque(false)
I will only see a white background, not the panel behind the editorpane.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Only create a panel with a certain background and place a JEditorPane on it. Set the editorpane to opaque(false) and have a look, if you see the panels color.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I would expect to see the color of the panel behind.
ACTUAL -
I only see a white field.

REPRODUCIBILITY :
This bug can be reproduced always.

Comments
EVALUATION This is a problem the the orginal design of Swing and how it has been confusing for years. The issue is setOpaque(false) has had a side effect in exiting LAFs which is that of hiding the background which is not really what it is ment for. It is ment to say that the component my have transparent parts and swing should paint the parent component behind it. Nimbus is the first Sun LAF to need transparency in components for rounded corners and outer glow focus. This means that in Nimbus most of the standard components are non-opaque by default. So setting them to non-opaque has no effect. JButton is nice that it has a setContentAreaPainted() method that can be used to turn off background painting but unfortunatly there has been no option for this with other Nimbus components such as JTextField. One workaround has been to set the background color to transparent like new Color(0,0,0,0). We have decided for this issue to make a color which is 100% transparent (eg, Alpha == 0) mean that the background will not be painted at all. So the solution for this bugs requirement is: textField.setBorder(BorderFactory.createEmptyBorder()); textField.setBackground(new Color(0,0,0,0)); Which will give you a textfield with no border or background.
29-05-2008

EVALUATION It works with the Metal LaF, assigned to the Nimbus owner import javax.swing.*; import java.awt.*; public class bug6687960 { private static void createGui() { final JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(new BorderLayout()); panel.setBackground(Color.red); frame.add(panel); JEditorPane pane = new JEditorPane(); pane.setOpaque(false); panel.add(pane); frame.setSize(200, 200); frame.setLocationRelativeTo(null); frame.setVisible(true); } public static void main(String[] args) throws Exception { SwingUtilities.invokeLater(new Runnable() { public void run() { bug6687960.createGui(); } }); } }
14-04-2008