Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java 3D > Exception when ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 1 Topic 747 of 818
Post > Topic >>

Exception when using dual head

by "Kevin" <flyfishco@[EMAIL PROTECTED] > Apr 12, 2007 at 08:45 AM

I ssaw a similar message on another group, but it didn't get a
response, but I'm sure it is more of a 3D issue.

I create a JFrame and display it on the first screen.  Everything
works well until I move the frame to the 2nd screen.  Redrawing the
universe produces the following exception:

Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException: adding a container to a container
on a different GraphicsDevice
	at java.awt.Component.checkGD(Unknown Source)
	at java.awt.Container.addImpl(Unknown Source)
	at java.awt.Container.add(Unknown Source)
	at com.issinc.sandbox.Java3DTest.redrawPanel(Java3DTest.java:95)
	at com.issinc.sandbox.Java3DTest.actionPerformed(Java3DTest.java:144)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
                ...

I've tried creating and getting the GraphicsConfiguration several
ways, but haven't found the right thing yet.

I'm getting this in our large application, but I recreated the
problemin the folowing code, based on the HelloUniverse example:



import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.*;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.vecmath.*;

import java.awt.FlowLayout;
import java.awt.GraphicsConfiguration;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * Simple Java 3D example program to display a spinning cube.
 */
public class Java3DTest extends javax.swing.JFrame implements
ActionListener {

	private javax.swing.JPanel drawingPanel;
    private JPanel buttonPanel;
    private JButton redrawButton;

    private SimpleUniverse univ = null;
    private BranchGroup scene = null;

    private Canvas3D c;

    public BranchGroup createSceneGraph() {
		// Create the root of the branch graph
		BranchGroup objRoot = new BranchGroup();

		// Create the TransformGroup node and initialize it to the
		// identity. Enable the TRANSFORM_WRITE capability so that
		// our behavior code can modify it at run time. Add it to
		// the root of the subgraph.
		TransformGroup objTrans = new TransformGroup();
		objTrans.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
		objRoot.addChild(objTrans);

		// Create a simple Shape3D node; add it to the scene graph.
		objTrans.addChild(new ColorCube(0.4));

		// Create a new Behavior object that will perform the
		// desired operation on the specified transform and add
		// it into the scene graph.
		Transform3D yAxis = new Transform3D();

		yAxis.rotX(Math.PI/8.0d);

		Alpha rotationAlpha = new Alpha(-1, 4000);

		RotationInterpolator rotator =
		    new RotationInterpolator(rotationAlpha, objTrans, yAxis,
					     0.0f, (float) Math.PI*2.0f);
		BoundingSphere bounds =
		    new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
		rotator.setSchedulingBounds(bounds);
		objRoot.addChild(rotator);

        // Have Java 3D perform optimizations on this scene graph.
        objRoot.compile();

		return objRoot;
    }

    private Canvas3D createUniverse() {
		// Get the preferred graphics configuration for the default screen
		GraphicsConfiguration config =
		    SimpleUniverse.getPreferredConfiguration();

		// Create a Canvas3D using the preferred configuration
		c = new Canvas3D(config);

		// Create simple universe with view branch
		univ = new SimpleUniverse(c);

		// This will move the ViewPlatform back a bit so the
		// objects in the scene can be viewed.
		univ.getViewingPlatform().setNominalViewingTransform();

		// Ensure at least 5 msec per frame (i.e., < 200Hz)
		univ.getViewer().getView().setMinimumFrameCycleTime(5);

		return c;
    }

    private void redrawPanel() {
    	// Create Canvas3D and SimpleUniverse; add canvas to drawing
panel
		c = createUniverse();

		// Create the content branch and add it to the universe
		scene = createSceneGraph();
		univ.addBranchGraph(scene);
		drawingPanel.add(c, java.awt.BorderLayout.CENTER);
		drawingPanel.revalidate();
    }

    /**
     * Creates new form HelloUniverse
     */
    public Java3DTest() {
		// Initialize the GUI components
		initComponents();
    }

    //
----------------------------------------------------------------

    private void initComponents() {
        drawingPanel = new javax.swing.JPanel();

 
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Java 3D Test");
        drawingPanel.setLayout(new java.awt.BorderLayout());

        drawingPanel.setPreferredSize(new java.awt.Dimension(250,
250));
        getContentPane().add(drawingPanel,
java.awt.BorderLayout.CENTER);

        // Add a button to redraw it...
        buttonPanel = new JPanel(new FlowLayout(FlowLayout.TRAILING));
        redrawButton = new JButton("Redraw");

        redrawButton.addActionListener(this);

        buttonPanel.add(redrawButton);
        getContentPane().add(buttonPanel,
java.awt.BorderLayout.SOUTH);

        pack();
    }

    /**
     * @[EMAIL PROTECTED]
 args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Java3DTest().setVisible(true);
            }
        });
    }

    public void actionPerformed(ActionEvent arg0)
	{
		redrawPanel();
	}
}


Any help is greatly appreciated.




 1 Posts in Topic:
Exception when using dual head
"Kevin" <fly  2007-04-12 08:45:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 23:20:03 CDT 2008.