Skip to main content

Small blank window in background

No replies
Joined: 2011-03-28

I modified the code to make it work. When I run this program, I get the main window, but there is also a smaller blank window in the background.
import com.sun.j3d.utils.geometry.Box;
import com.sun.j3d.utils.universe.SimpleUniverse;
import java.awt.BorderLayout;
import java.awt.GraphicsConfiguration;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.vecmath.AxisAngle4d;
import javax.vecmath.Vector3f;
* This is our first simple program that creates a cube. We have no lighting
* defined so the object appears a bright white color. The cube is tilted
* slightly so that we can see its shape by creating a transform group.
public final class SimpleWorld extends JFrame implements ActionListener {
* The canvas 3D used to display the scene.
GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
protected Canvas3D myCanvas3D = new Canvas3D(config);
* The AWT button used to exit the application.
protected JButton myButton = new JButton("Exit");
* This function builds the view branch of the scene graph. It creates a
* branch group and then creates the necessary view elements to give a
* useful view of our content.
* @param c Canvas3D that will display the view
* @return BranchGroup that is the root of the view elements
protected BranchGroup buildViewBranch(Canvas3D c) {
//This is the root of our view branch
BranchGroup viewBranch = new BranchGroup();
//The transform that will move our view
//back 5 units along the z-axis
Transform3D viewXfm = new Transform3D();
viewXfm.set(new Vector3f(0.0f, 0.0f, 5.0f));
//The transform group that will be the parent
//of our view platform elements
TransformGroup viewXfmGroup = new TransformGroup(viewXfm);
ViewPlatform myViewPlatform = new ViewPlatform();
//Next the physical elements are created
PhysicalBody myBody = new PhysicalBody();
PhysicalEnvironment myEnvironment = new PhysicalEnvironment();
//Then we put it all together
View myView = new View();
return viewBranch;
* This builds the content branch of our scene graph. It uses the buildCube
* function to create the actual shape, adding to to the transform group so
* that the shape is slightly tilted to reveal its 3D shape.
* @param shape Node that represents the geometry for the content
* @return BranchGroup that is the root of the content branch
protected BranchGroup buildContentBranch(Node shape) {
//Create the branch group that will be the root of the content branch
BranchGroup contentBranch = new BranchGroup();
//Create the transform that will cause the shape to appear tilted
Transform3D rotateCube = new Transform3D();
rotateCube.set(new AxisAngle4d(1.0, 1.0, 0.0, Math.PI / 4.0));
TransformGroup rotationGroup = new TransformGroup(rotateCube);
//Put the branch together
return contentBranch;
* This constructs a cube as an array of quadrilateral polygons. There are
* six faces, each with four vertices (obviously!). The cube extends 1 unit
* along each axis in the positive and negative directions and is centered
* on the origin.
* @return Shape3D that is the cube
protected Box buildCube() {
Box cube = new Box();
Appearance ap = new Appearance();
ColoringAttributes color = new ColoringAttributes();
color.setColor(1f, 1f, 1f);
return cube;
* Handles the exit button action to quit the program.
public void actionPerformed(ActionEvent e) {
* This creates a default universe and locale, creates a window and uses the
* functions defined in this class to build the view and content branches of
* the scene graph.
public SimpleWorld() {
//Create a default universe and locale
SimpleUniverse myUniverse = new SimpleUniverse();
Locale myLocale = new Locale(myUniverse);
//Use the functions to build the scene graph
//Do some AWT stuff to set up the window
setSize(400, 400);
setLayout(new BorderLayout());
add("Center", myCanvas3D);
add("South", myButton);
* Just create the class and run!
public static void main(String[] args) {
SimpleWorld sw = new SimpleWorld();
Can someone help me get rid of that blank window?