Skip to main content

adding a container to a container on a different GraphicsDevice

3 replies [Last post]
Joined: 2005-10-05

I have the following problem.
An application with two parts: the left part I use for the Canvas3D, the right part to display some information, like GoogleEarth. I use for that the JSplitPane, with left component the Canvas3D and right component an JPanel.

I have two monitors and with an Intel GMA I had no problem at all (with Linux). But now I have a Nvidia (also Linux) and I always get an

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding a container to a container on a different GraphicsDevice

It'll be ok if the window is first displayed on the primary monitor but if the window is on the attached monitor I get this exception if I change the size of the split.

The full error is:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: adding a container to a container on a different GraphicsDevice
at java.awt.Component.checkGD(
at java.awt.Container.addImpl(
at javax.swing.JSplitPane.addImpl(
at java.awt.Container.add(
at javax.swing.JSplitPane.setLeftComponent(
at javax.swing.plaf.basic.BasicSplitPaneUI.addHeavyweightDivider(
at javax.swing.plaf.basic.BasicSplitPaneUI.startDragging(
at javax.swing.plaf.basic.BasicSplitPaneDivider.prepareForDragging(
at javax.swing.plaf.basic.BasicSplitPaneDivider$MouseHandler.mousePressed(
at java.awt.Component.processMouseEvent(
at java.awt.Component.processEvent(
at java.awt.Container.processEvent(
at java.awt.Component.dispatchEventImpl(
at java.awt.Container.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.LightweightDispatcher.retargetMouseEvent(
at java.awt.LightweightDispatcher.processMouseEvent(
at java.awt.LightweightDispatcher.dispatchEvent(
at java.awt.Container.dispatchEventImpl(
at java.awt.Window.dispatchEventImpl(
at java.awt.Component.dispatchEvent(
at java.awt.EventQueue.dispatchEvent(
at java.awt.EventDispatchThread.pumpOneEventForFilters(
at java.awt.EventDispatchThread.pumpEventsForFilter(
at java.awt.EventDispatchThread.pumpEventsForHierarchy(
at java.awt.EventDispatchThread.pumpEvents(
at java.awt.EventDispatchThread.pumpEvents(

Anyway, that works fine on the primary monitor but not on the attached.
Please help, Erwin.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-07-17


Check if below code helps you :


* Creates a Canvas3D instance.

* This method targets multi screen systems, where Canvas3D may be
* placed in other Screen then DefaultScreen device.
* @param compForCanvas - Component which will hold-on a Canvas3D. If null or
* not yet added to a container, this method will use
* default screen device.

* The parameter compForCanvas can be an instance of java.applet.Applet,
* java.awt.Window, java.awt.Frame, javax.swing.JFrame and their sub-classes,
* as well an instance of JPanel already attached to one of previous cited Containers.
* @return a Canvas3D instance multi-screen/multi-head aware.
public static Canvas3D createCanvas3D(java.awt.Component compForCanvas) {
GraphicsDevice graphicsDevice;

if (compForCanvas.getGraphicsConfiguration() != null) {
// component is, or belongs to, a live container
graphicsDevice = compForCanvas.getGraphicsConfiguration().getDevice();
} else {
// component is not alive yet, use default graphics device
graphicsDevice = GraphicsEnvironment.getLocalGraphicsEnvironment()

GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
// change template settings here

GraphicsConfiguration config = graphicsDevice.getBestConfiguration(template);

return new Canvas3D(config);


Joined: 2005-10-05

Thank you, but it's still the same behaviour. On the primary screen it's work but not on the attached screen. Just clicking (no resizing, just click with the mouse) on the bar from the split pane triggers the exception.

Joined: 2008-09-18


I had the same problem. I fixed it. I wrote the function

public static GraphicsConfiguration getPreferredConfiguration(GraphicsDevice device)
GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
String stereo;


// Check if the user has set the Java 3D stereo option.
// Getting the system properties causes appletviewer to fail with a
// security exception without a try/catch.

stereo = (String)
public Object run()
return System.getProperty("j3d.stereo");

// update template based on properties.
if (stereo != null)
if (stereo.equals("REQUIRED")) template.setStereo(GraphicsConfigTemplate.REQUIRED);
else if (stereo.equals("PREFERRED")) template
// Return the GraphicsConfiguration that best fits our needs.
return device.getBestConfiguration(template);


The Parameter GraphicsDevice you can get from your component (frame, panel...) object:

This will work on both screens.