Its been more than a year since my initial post, and I have recently updated to Jogl 1.1 and JRE 1.5, but the problem I described initially persists. I have finally taken the time to boil my rather complex code down to the essentials. I invite anyone to compile and execute the code given below. A GLCanvas is placed on each of two tabs in a JTabbedPane. On closing the application, a dialog appears; select “No” to resume, then switch tabs. The graphic on the tab not visible when the dialog was opened is now gone, with seemingly no way to recover. As stated in my original post, this behavior occurs on my desktop machine but not my laptop. Any ideas are welcome.
import java.awt.;
import java.awt.event.;
import javax.swing.;
import javax.swing.event.;
import net.java.games.jogl.*;
public class JoglTest extends JFrame {
public static void main (String [] args) {
EventQueue.invokeLater (new Runnable () {
public void run () {
new JoglTest ();
}
});
}
private JoglTest () {
setTitle ("JoglTest");
setSize (640, 480);
setDefaultCloseOperation (WindowConstants.DO_NOTHING_ON_CLOSE);
addWindowListener (new WindowAdapter () {
public void windowClosing (WindowEvent event) {
String query = "Do you wish to exit?";
int opt = JOptionPane.showConfirmDialog (JoglTest.this, query, "", JOptionPane.YES_NO_OPTION);
if (opt != JOptionPane.YES_OPTION) return;
System.exit (1);
}
});
JTabbedPane tp = new JTabbedPane ();
tp.addTab ("black", new JoglTab (Color.black));
tp.addTab ("red", new JoglTab (Color.red));
add (tp, BorderLayout.CENTER);
setVisible (true);
}
//Inner Class
class JoglTab extends JPanel implements GLEventListener {
Color axisColor;
public JoglTab (Color axisColor) {
this.axisColor = axisColor;
GLCapabilities caps = new GLCapabilities ();
GLCanvas canvas = GLDrawableFactory.getFactory ().createGLCanvas (caps);
canvas.addGLEventListener (this);
setLayout (new BorderLayout ());
add (canvas, BorderLayout.CENTER);
}
//GLEventListener Interface
public void display (GLDrawable drawable) {
GL gl = drawable.getGL();
float [] bg = Color.white.getColorComponents (null);
gl.glClearColor (bg [0], bg [1], bg [2], 0.0f);
gl.glClear (GL.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode (GL.GL_MODELVIEW);
gl.glLoadIdentity ();
//Draw Axes
gl.glColor3fv (axisColor.getColorComponents (null));
gl.glBegin (GL.GL_LINES);
gl.glVertex2d (-1d, 0d);
gl.glVertex2d (+1d, 0d);
gl.glVertex2d (0d, -1d);
gl.glVertex2d (0d, +1d);
gl.glEnd ();
}
public void displayChanged (GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
public void init (GLDrawable drawable) {}
public void reshape (GLDrawable drawable, int x, int y, int width, int height) {
GL gl = drawable.getGL ();
GLU glu = drawable.getGLU ();
gl.glViewport (0, 0, width, height); //set the current viewport
gl.glMatrixMode (GL.GL_PROJECTION);
gl.glLoadIdentity ();
glu.gluOrtho2D (-1d, +1d, -1d, +1d);
}
}
}