Java3D in a Swing Application..

I want to create a Swing application to display two 3D models in viewports similar to the kind you’d see in programs like 3D modellers…

I’m ok with my current understand of Swing and seperately with Java 3D (in creating applets) but i’ve never had any experience in bringing the two together and I’ve read around the net and it seems like its an area where people seem to have alot of problems…

The question i’d like to raise is what component do I use to display my Java3D model scene in an application frame? would I embedd a canvas3D object into a container like a panel or would that be impossible/too slow?

Or would I have to (or would it be easier to…) create a pop-up window or even a pop-up applet to display my Java3D scene?

And lastly is the use of Swing even reccomended in this or should I revert back to using awt for compatibility?

hope someone can help?

FlyingGuns actually is a Swing app with Java3D included.

Just avoid Java3D in JInternalFrames, JSplitPane caused some problems as well (maybe they have been sorted out with latest Java3D releases).

You can put a Canvas3D inside a JPanel, but you will want to organize your layout up-front to make sure the Canvas3D doesn’t overlap with any other Swing component, because the Canvas3D (heavyweight) will eclipse the lightweight component. I have used a Canvas3D inside a TabPane with no problem, as long as I detach any live BranchGroups when switching tabs (however this causes a delay depending on the size of your BranchGroup).

You can also use two Canvas3Ds, perhaps side-by-side in different JPanels. Your performance will degrade, however, because you’ll be splitting CPU between the two Canvas3D’s.

If you want to draw any swing stuff above the Canvas3D you can use a Panel (yes a Panel not a JPanel) and add the swing stuff to the Panel. This way the heavyweight Panel draws above the canvas, but doesn’t draw above the Swing :wink:

Sure, that’d work too, I think, though I haven’t tried it myself.

That’s basically the way a JFrame or JDialog works, since they both have heavyweight native peers (IIRC).

Sounds awesome i think i’ll do that…

Although u’ve raised a concern for me… In my program I intend to use at most two canvas3D’s in the application…

They will only be displaying animations of single 3D models (built entirely using primitives) walking seperately…

So I’m curious,
Do you think the performance will degrade terribly when both canvas’s are active?