Posted by
Julien on
Dec 19, 2013; 11:22pm
URL: https://forum.jogamp.org/JTabbedPane-Canvas3D-bug-tp4030983.html
Dear List,
First off, a huge thanks to all of those who have kept this project alive. I am a developer from the Unidata IDV team (
http://www.unidata.ucar.edu/software/idv/) and we have relied on this project for 10+ years for 3D visualization.
We have been using Java 3D (1.6.0-pre9-daily-experimental daily) on OS X and Java 7 with mostly good results, but we have come across a bug where the behavior of a
Java Swing object (javax.swing.JTabbedPane) is problematic when working with javax.media.j3d.Canvas3D objects. I have attempted to write a minimal example demonstrating this issue:
public class Bug extends JPanel {
public Bug() {
super(new GridLayout(1, 1));
JTabbedPane tabbedPane = new JTabbedPane();
JPanel jp1 = new JPanel();
jp1.setLayout(new BorderLayout());
jp1.add(canvas3d(1.0f, 1.0f, 0.0f));
JPanel jp2 = new JPanel();
jp2.setLayout(new BorderLayout());
jp2.add(canvas3d(0.0f, 1.0f, 1.0f));
tabbedPane.addTab("Tab 1", jp1);
tabbedPane.addTab("Tab 2", jp2);
add(tabbedPane);
}
public static Canvas3D canvas3d(float arg0, float arg1, float arg2) {
Canvas3D canvas =
new Canvas3D(SimpleUniverse.getPreferredConfiguration());
SimpleUniverse universe = new SimpleUniverse(canvas);
BranchGroup root = new BranchGroup();
Appearance polygon1Appearance = new Appearance();
polygon1Appearance.setColoringAttributes(
new ColoringAttributes(new Color3f(arg0, arg1, arg2), 1));
QuadArray polygon1 = new QuadArray(4, QuadArray.COORDINATES);
polygon1.setCoordinate(0, new Point3f(0f, 0f, 0f));
polygon1.setCoordinate(1, new Point3f(5f, 0f, 0f));
polygon1.setCoordinate(2, new Point3f(5f, 3f, 0f));
polygon1.setCoordinate(3, new Point3f(0f, 3f, 0f));
root.addChild(new Shape3D(polygon1, polygon1Appearance));
universe.addBranchGraph(root);
universe.getViewingPlatform().setNominalViewingTransform();
return canvas;
}
private static void createAndShowGUI() {
JFrame frame = new JFrame();
frame.setPreferredSize(new Dimension(200, 200));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new Bug(), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
When running the Bug.java main application, you will note that switching back and forth between tabs works as expected on Java 3D 1.5 / Java 6 / OS X. However, switching between tabs in Java 3D 1.6 / Java 7 / OS X results in the image contained by the second tab getting stuck no matter what tab you are on.
Again, many thanks for your help.
-Julien