Sergey has posted 7 posts at DZone. You can read more from them at their website. View Full User Profile

How Do I Use Java3D with JavaFX?

  • submit to reddit

What is Java3D? It is an API enabling applications that call functions of the OpenGL and DirectX drivers to create and render 3D scenes on the screen. How can we use that from JavaFX?You can download the free API at the Java3D project page:


The following files will appear after successful installation of the distribution kit:

C:\Program Files\Java\Java3D\1.5.1\lib\ext\j3dcore.jar
C:\Program Files\Java\Java3D\1.5.1\lib\ext\j3dutils.jar
C:\Program Files\Java\Java3D\1.5.1\lib\ext\vecmath.jar

These files should be included in the NetBeans project.

The API enables you to render a 3D scene on a Canvas3D class panel derived from the java.awt.Panel class.

In this demo, you will create a class inherited from Panel, and its createComponent method will return a javax.swing.JPanel object with the embedded Canvas3d object. You can test this approach on the rotating cub demo code available at the following page:

Add a coulple of buttons to alter rotation direction. The figure below shows the final form.

Since scene rendering is executed by the co-processor, the speed of the cub rotation does not influence rendering quality.


package javafx3d;

import javafx.ui.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;
import javax.vecmath.*;
import java.lang.Math;
import java.awt.BorderLayout;
import javax.swing.JPanel;

class RenderPanel extends Panel {
public attribute rotator:RotationInterpolator;
operation RenderPanel.createComponent() {
var config = SimpleUniverse.getPreferredConfiguration();
var c = new Canvas3D(config);
var univ = new SimpleUniverse(c);
var objRoot = new BranchGroup();
var objTrans = new TransformGroup();
objTrans.addChild(new ColorCube(0.4));
var rotationAlpha = new Alpha( -1, 999);
rotator = new RotationInterpolator(rotationAlpha, objTrans);
var t = new Transform3D();
var axis = new Transform3D(t);
var bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
var panel=new JPanel();
panel.setLayout(new BorderLayout());
panel.add(c, BorderLayout.CENTER);
return panel;
var renderPanel=new RenderPanel();
Frame {
visible: true
screenx: 50
screeny: 100
width: 600
height: 400
content: BorderPanel {
border: EmptyBorder {left: 16 top: 16 right: 16 bottom: 16}
center: BorderPanel {
background: new Color(1,1,1,1)
center: renderPanel
right: BorderPanel {
border: EmptyBorder {left: 16 top: 0 right: 0 bottom: 0}
top: GridPanel {
rows: 4
columns: 1
cells: [
Button {
text: "Horizontal"
action: operation(){
var t = new Transform3D();
var axis = new Transform3D(t);
,Button {
text: "Vertical"
action: operation(){
var t = new Transform3D();
var axis = new Transform3D(t);
Your rating: None Average: 1 (1 vote)
Published at DZone with permission of its author, Sergey Surikov.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)



Fran Aviles replied on Fri, 2008/02/29 - 1:30pm

Just like in pure Java

Sergey Surikov replied on Fri, 2008/02/29 - 2:19pm




Andres Almiray replied on Fri, 2008/02/29 - 2:50pm in response to: Sergey Surikov

Which begs the question: what can JavaFX offer to 2D&3D mixed together? isn't there something new under the Sun?

I hope we would see some jfx 3d extensions in the future that would make creating 3d scenes much easier, this example looks like a C&P from a regular Java3D example. 

Dmitri Trembovetski replied on Fri, 2008/02/29 - 4:04pm in response to: Andres Almiray


> I hope we would see some jfx 3d extensions


Some of this is in the works already, a 3d scenegraph:

> As many of you are aware, Sun's emphasis on client technologies has led to the creation of JavaFX -- a platform for creating rich content applications for mobile, set-top, and desktop devices. The majority of our current effort is focused on building out the 3D support for JavaFX.



Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.