setVisible canvas3D bug
Posted by plocatel_ on Oct 14, 2013; 2:29pm
URL: https://forum.jogamp.org/setVisible-canvas3D-bug-tp4030251.html
Hello,
I am porting my Java application from java3D 1.5.2, on Windows everything is OK, but I have a problem with Mac OS X 10.8.4.
First, I had a problem with the position of the canvas3D element, I solved this problem with the topic "Mac Canvas3D location bug".
But now I have a problem with the visibility of the Canvas3D element:
My application is composed of 3 tabs, each tab contains 2 or 3 canvas3D, and all the canvas are still displayed.
I try also to hide useless canvas by using the setVisible method, moving them out of the screen or resizing them with a 0px width but nothing work. The canvas are always displayed.
So how can I fix this problem of visible/hidden canvas ?
Thank you for your help and sorry for my bad English.
Paul.
To reproduce :
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Canvas3D;
import javax.media.j3d.GraphicsConfigTemplate3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.swing.JApplet;
import javax.swing.JButton;
import com.sun.j3d.utils.geometry.ColorCube;
import com.sun.j3d.utils.universe.SimpleUniverse;
public class Canvas3DVisibleTest extends JApplet{
JApplet applet;
public Canvas3DVisibleTest (JApplet applet) {
this.applet = applet;
}
public void init() {
// Create a simple scene with a rotated color cube
BranchGroup root = new BranchGroup();
Transform3D rotation = new Transform3D();
rotation.rotX(Math.PI / 9);
TransformGroup rotationGroup = new TransformGroup(rotation);
root.addChild(rotationGroup);
rotationGroup.addChild(new ColorCube(0.5f));
GraphicsConfiguration config = GraphicsEnvironment
.getLocalGraphicsEnvironment().getDefaultScreenDevice()
.getBestConfiguration(new GraphicsConfigTemplate3D());
final Canvas3D canvas3D = new Canvas3D(config);
canvas3D.setBackground(new Color(0,0,0));
canvas3D.setSize(100, 100);
SimpleUniverse universe = new SimpleUniverse(canvas3D);
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(root);
JButton button = new JButton("Visible / Hidden");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
canvas3D.setVisible(! canvas3D.isVisible());
}
});
applet.setLayout(new FlowLayout());
applet.add(canvas3D);
applet.add(button);
}
}