Hi,
Here's some source code that works.
--
Renoir Sewjee
Software Engineer
ISS International (Welkom)
Tel: +27 (0)57 912 2702
Fax: +27 (0)57 912 2652
--
import java.awt.Dimension;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.JSplitPane;
import javax.swing.JScrollPane;
import javax.vecmath.Point3d;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.Appearance;
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.Sphere;
import com.sun.j3d.utils.behaviors.vp.OrbitBehavior;
public class Canvas3DPanel extends JPanel
{
public Canvas3DPanel()
{
super(new BorderLayout());
Canvas3D canvas = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
canvas.setDoubleBufferEnable(true);
add(canvas, BorderLayout.CENTER);
setMinimumSize(new Dimension(0, 0));
setMaximumSize(new Dimension(0, 0));
SimpleUniverse universe = new SimpleUniverse(canvas);
universe.getViewingPlatform().setNominalViewingTransform();
BranchGroup root = new BranchGroup();
root.addChild(new Sphere(1.0f, Sphere.GENERATE_NORMALS, new Appearance()));
OrbitBehavior orbitter = new OrbitBehavior(canvas);
orbitter.setSchedulingBounds(new BoundingSphere(new Point3d(),
Double.MAX_VALUE));
orbitter.setViewingPlatform(universe.getViewingPlatform());
root.addChild(orbitter);
root.compile();
universe.addBranchGraph(root);
}
public static void main(String[] args)
{
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
new JScrollPane(new JTree()),
new Canvas3DPanel());
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(200);
JFrame frame = new JFrame("Canvas3D in SplitPane Test");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(splitPane);
frame.setSize(600, 480);
frame.setVisible(true);
}
}