Hi,
I'm trying to display a Canvas3D in JTable. Following problem occurs:
As you can see in the source code below I'm extending the class Panel
(or JPanel). In my class J3DPanel I'm using a Canvas3D and setting the
bounds. Assigning my class to a Frame will always fill the full Frame
with the Canvas3D, despite to my calls to setBounds, setSize etc.
My question: Is there any way to set the size and location of an
Canvas3D so I can display it inside a JTable?
I'm using a Macintosh with OS X if this is of interest.
Cheers,
Jörg
-----------
package sse;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import javax.swing.JPanel;
import java.awt.Panel;
import java.awt.Rectangle;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.image.*;
import com.sun.j3d.utils.universe.*;
import javax.media.j3d.*;
import javax.vecmath.*;
public class J3DPanel extends Panel {
SimpleUniverse universe = null;
Canvas3D canvas = null;
public J3DPanel() {
init();
}
public void setBounds(int x, int y, int width, int height) {
super.setBounds(x,y,width, height);
canvas.setBounds(x, y, width, height);
repaint();
}
public BranchGroup createSceneGraph() {
BranchGroup RootBG = new BranchGroup();
TransformGroup SphereTG = new TransformGroup();
Transform3D SphereT3D = new Transform3D();
Appearance SphereAppearance = new Appearance();
AmbientLight ALgt = new AmbientLight(new Color3f(1f, 1f, 1f));
DirectionalLight DLgt = new DirectionalLight(new Color3f(1f, 1f, 1f),
new Vector3f( -0.5f, -0.5f, -1f));
BoundingSphere BigBounds = new BoundingSphere(new Point3d(), 100000);
ALgt.setInfluencingBounds(BigBounds);
DLgt.setInfluencingBounds(BigBounds);
SphereT3D.setTranslation(new Vector3f(0f, 0f, -1.5f));
SphereTG.setTransform(SphereT3D);
SphereAppearance.setMaterial(new Material(new Color3f(0f, 0f, 1f),
new Color3f(0f, 0f, 0f),
new Color3f(1f, 0f, 0f),
new Color3f(1f, 1f,
1f), 100f));
SphereTG.addChild(new Sphere(1.0f, Sphere.GENERATE_NORMALS, 40,
SphereAppearance));
RootBG.addChild(SphereTG);
RootBG.addChild(ALgt);
RootBG.addChild(DLgt);
RootBG.compile();
return RootBG;
}
public void init() {
setLayout(new BorderLayout());
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
canvas = new Canvas3D(config);
canvas.setSize(100,100);
Rectangle r;
r=canvas.getBounds();
System.out.println("Rectangle:" + r.x + " " + r.y + " " +
r.width + " " + r.height);
add("Center", canvas);
universe = new SimpleUniverse(canvas);
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(createSceneGraph());
}
}
Jörg Höhne - 27 Dec 2004 13:11 GMT
The dim lit never dies. I didn't turn of the layout manager of the
frame where the Canvas3D was displayed. With setLayout(null) it works
fine.
Thanks,
Jörg
On 2004-12-27 08:40:53 +0100, =?ISO-8859-1?Q?J=F6rg_H=F6hne?=
<sync@freenet.de> said:
> Hi,
> I'm trying to display a Canvas3D in JTable. Following problem occurs:
[quoted text clipped - 90 lines]
> }
> }