Hello,

I have a canvas 3D in a JPanel used as content pane for a JFrame. I use it
to display a small scene... everything is ok. Then I remove it from the
JPanel and create a new Canvas and as I try to show the same(or other) scene
in the new canvas I get e Dr.Watson Message!!!
If I don't remove the old one, but still use the new for display It
works!!!!!!!

I have a sample code, to show this problem, bellow. I you press the Button
the old Canvas is removed and a new one is created.

thankx

Rui Prada

----------------------------------------------------------------------------
-------------------
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.ColorCube;

public class Test extends JFrame {

  JPanel contentPane;
  Canvas3D c;
  VirtualUniverse universe;
  Locale locale;
  View view;
  TransformGroup viewTransform;
  BranchGroup viewBG;

  Test() {
    setSize(800,600);
    createContentPane();
    createCanvas();
    createUniverse();
    loadScene();
  }

  public void createContentPane() {
    contentPane = new JPanel(null);
    setContentPane(contentPane);
    JButton b = new JButton("TEST");
    b.setBounds(600,450,100,50);
    b.addActionListener(new ActionListener1());
    contentPane.add(b);
    show();
  }

  public void createCanvas() {
    GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
    c = new Canvas3D(config);
    c.setBounds(50,50,500,400);
    contentPane.add(c);
  }

  public void createUniverse() {
    universe = new VirtualUniverse();
    locale = new Locale(universe);
    view = new View();
    view.setPhysicalBody(new PhysicalBody());
    view.setPhysicalEnvironment(new PhysicalEnvironment());
    ViewPlatform vp = new ViewPlatform();
    view.attachViewPlatform(vp);
    viewTransform = new TransformGroup();
    viewTransform.addChild(view.getViewPlatform());
    view.addCanvas3D(c);
    viewBG = new BranchGroup();
    viewBG.addChild(viewTransform);
    locale.addBranchGraph(viewBG);
  }

  public void loadScene() {
    BranchGroup bg = new BranchGroup();
    Transform3D t3d = new Transform3D();
    t3d.setTranslation(new Vector3f(0.0f,0.0f,-5.0f));
    TransformGroup tg = new TransformGroup(t3d);
    tg.addChild(new ColorCube(1.0));
    bg.addChild(tg);
    locale.addBranchGraph(bg);
  }

  public void close() {
    view.removeCanvas3D(c);
    view = null;
    universe = null;
    locale = null;
    viewTransform = null;
    // Hide this line and this starts working!!!
    contentPane.remove(c);
    c.setVisible(false);
    contentPane.repaint();
  }

  public static void main(String[] args) {
    new Test();
  }

  class ActionListener1 implements ActionListener {
    public void actionPerformed(ActionEvent ev) {
      close();
      createCanvas();
      contentPane.add(c);
      createUniverse();
      loadScene();
    }
  }
}

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to