JDK-4683253 : REGRESSION: black or mysterious background in Container
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux
  • CPU: x86
  • Submitted: 2002-05-10
  • Updated: 2002-10-15
  • Resolved: 2002-10-15
Related Reports
Relates :  
Relates :  
Description

Name: gm110360			Date: 05/10/2002


FULL PRODUCT VERSION :
java version "1.4.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed code)

OPERATING SYSTEM: SuSE Linux 7.3j

# rpm -qa | grep glibc
glibc-2.2.4-40

# uname -a
Linux 2.4.16 i686 unknown


A DESCRIPTION OF THE PROBLEM :
I am using JFrame for my application. In order to share
classes, I created an extension of java.awt.Container and
added this container via myFrame.setContentPane(cont). Every
time I start the application I get a black or colourful
distorted background although I tried
cont.setBackground(Color.white). When I maximize the window,
the background is always black (but input fields are shown
correct).

REGRESSION.  Last worked in version 1.3.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create an extension of java.awt.Container
2. create a new JFrame and set the content pane
3. set the background colour of the container

EXPECTED VERSUS ACTUAL BEHAVIOR :
I wanted to have a white background :-) It seems that
setBackground has no effect.

This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Container;
import javax.swing.JFrame;
import java.awt.Color;

class MyContainer extends Container {
        MyContainer() {
                super();
        }
}

class MyApp extends JFrame {
        public static void main(String args[]) {
                new MyApp();
        }

        MyApp() {
                super("My Application");
        
                MyContainer cont = new MyContainer();
                cont.setBackground(Color.white);

                this.setContentPane(cont);

                this.show();
        }
}
---------- END SOURCE ----------

Release Regression From : 1.3.1_03
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.

(Review ID: 146276) 
======================================================================

Comments
EVALUATION I can also reproduce this problem on Solaris 7. The docs for JFrame.setConentPane() recommend using a JComponent as the content pane, however that doesn't help the problem. ###@###.### 2002-05-13 Name: ssR10077 Date: 07/01/2002 Probably the same problem as 4458337. ====================================================================== I don't believe this is a 2D issue. When run on 1.4.1 with tracing on (-Dsun.java2d.trace=log), one can see that there are only two calls to the Blit primitive, which is back-buffer to the screen copy, no FillRects. If the 'setContentPane()' call is commented out, the FillRect's show up. When MyContainer class from the test case in the description was modified to have a paint(Graphics) method as follows: public void paint(Graphics g) { super.paint(g); g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); } the result was as expected - the container would appear with white background, in 1.3.1 and 1.4. Also, this is not a regression: I can observe the same behavior in 1.3.1, with the only difference being that the color of the frame's background would appear to be the default swing color instead of the default desktop color in 1.4.x . So it looks like swing repainting mechanism doesn't work too well if the content pane is replaced with non-swing container. Reassigning to Swing team for further investigation. ###@###.### 2002-10-15 Swing's painting architecture requires the content pane to be opaque, this is indicated in JFrame's.setContentPane javadoc (and a couple of other places): * Swing's painting architecture requires an opaque <code>JComponent</code> * in the containment hiearchy. This is typically provided by the * content pane. If you replace the content pane it is recommended you * replace it with an opaque <code>JComponent</code>. If you change MyContainer to extend JPanel and invoke setOpaque(true);, all is well. ###@###.### 2002-10-15
15-10-2002