JDK-8039795 : Component loses its GraphicsConfiguration when added to a Container
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u45,8,9
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • Submitted: 2014-02-04
  • Updated: 2015-10-02
  • Resolved: 2015-10-02
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 9
9Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Red Hat Enterprise Linux Workstation release 6.3 (Santiago)


A DESCRIPTION OF THE PROBLEM :
When we create a component with a specific GraphicsConfiguration assigned to it. ex. new Canvas(gc), and add it to a Container (ex. JPanel) , the component loses its own GC and is overwritten by the GC of the Container.  This happens even if the component and the container use the same GraphicsDevice. 

This happens in Container.addImpl(Component comp, Object constraints, int index) method. This did not happen in Java 6 and seems to be introduced in Java 7 onwards. 

Use case:
To render stereo in Linux, a canvas needs to be constructed with a special GraphicsConfiguration that has a stereo capable visual.  When one such canvas is constructed and then added to its parent (JPanel), the GC of JPanel overwrites the GC of the canvas. This makes the canvas lose the stereo rendering capability.  The GC of the JPanel can either be null or a default GC for the default screen device based on runtime. 

There seems to be no way to set the GC on the canvas after it is constructed. (atleast not exposed outside java) . 

Also reparenting happens multiple times in my application, Fullscreen/Docking-undocking etc. So this scenario happens a lot of times where i run into problems because of this issue. 

it is to be noted that remove() also has a similar problem where it resets the GC to null forcefully.



REGRESSION.  Last worked in version 6u43

ADDITIONAL REGRESSION INFORMATION: 
java version "1.6.0_17"
Java(TM) SE Runtime Environment (build 1.6.0_17-b04)
Java HotSpot(TM) 64-Bit Server VM (build 14.3-b01, mixed mode)


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
		JPanel panel = new JPanel();
		GraphicsConfiguration gc= GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getConfigurations()[0];
		Canvas c = new Canvas(gc);
		System.out.println(c.getGraphicsConfiguration());
		panel.add(c);
		System.out.println(c.getGraphicsConfiguration());

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x21]
X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x21]

ACTUAL -
X11GraphicsConfig[dev=X11GraphicsDevice[screen=0],vis=0x21]
null

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package com.lgc.sgl.core;

import java.awt.Canvas;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;

import javax.swing.JPanel;

public class TestGC {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JPanel panel = new JPanel();
//get a specific GC - lets say this is stereo capable
		GraphicsConfiguration gc= GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getConfigurations()[0];
		Canvas c = new Canvas(gc);
		System.out.println(c.getGraphicsConfiguration());
		panel.add(c);
//Adding to panel makes the canvas lose its GC
		System.out.println(c.getGraphicsConfiguration());
		

	}

}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
For the simple case shown above, I am using reflection to set the GC back on the canvas, with supporting calls to addNotify() and removeNotify() to forcefully recreate the peer. 

However this does not work when doing complicated actions like docking-undocking between 2 monitors(different GraphicsDevices). I run into NullPointerException on the XWindow classes which i don't have access to. 


Comments
not a regression in 8 or 9
16-05-2014

Yes, it is.
10-04-2014

is it affecting 8 or 9?
09-04-2014