posted on: 2010-04-12 14:24:20
How to get around
java.lang.IllegalArgumentException: adding a container to a container on a different GraphicsDevice
>I have found a way to get around a
java.lang.IllegalArgumentException: adding a container to a container on a different GraphicsDevice
The problem is caused by using a SimpleUniverse to generate a GraphicsConfiguration.
import java.awt.GraphicsConfiguration; import java.awt.GraphicsDevice; import java.awt.GraphicsEnvironment; import java.awt.Frame; /** * Gets the best graphics conifguration to display on the current device. * * @param frame frame that you want to add a Canvas3d to */ public static GraphicsConfiguration getBestConfigurationOnSameDevice(Frame frame){ GraphicsConfiguration gc = frame.getGraphicsConfiguration(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice[] gs = ge.getScreenDevices(); GraphicsConfiguration good = null; GraphicsConfigTemplate3D gct = new GraphicsConfigTemplate3D(); for(GraphicsDevice gd: gs){ if(gd==gc.getDevice()){ good = gct.getBestConfiguration(gd.getConfigurations()); if(good!=null) break; } } return good; }
Comments
jaume
2011-03-11 04:00:38
Nice! I just copied and pasted and it fixed my error. I'm in Ubuntu + dual screen + NVidia drivers. When I create the View in my left screen (main monitor) it worked fine and I can move it to the second screen. However, it was not possible to create the window directly in the second. Now, it is possible. I notice that the performance is lower, though: less frame rate, antialiasing seems to be broken and so. Do you have an explanation for this?
Anyway, thank you very much. You already solved a very annoying issue I had.
Matt
2011-03-12 10:24:54
I really don't know. I suspect that the device being used is different, you could try returning returning a different configuration then the getBestConfiguration. Also there are the java3d forums, which seem pretty active and somebody is likely to answer your question.