We’ve run into similar issues with an application we’re building in-house.
First, you can work around the repeated calls to GLEventListener.init() by causing your GLJPanel to share textures and display lists with a 1x1 GLPbuffer that you create up front. This way, even though init() is called multiple times, you don’t need to reload the textures, but can reuse the texture IDs since the presence of the pbuffer’s OpenGL context will prevent the textures from being deleted by OpenGL.
You can also work around the repeated calls to GLJPanel.addNotify() and removeNotify(). Basically, you can subclass the GLJPanel and override these methods. You can consider the first call to addNotify() to have created the GLJPanel and ignore subsequent calls to addNotify(). You can add a method like “destroy()” to your GLJPanel subclass which simply sets a “destroyed” flag and calls removeNotify(). Finally, you can override removeNotify() and check the destroyed flag, only calling super.removeNotify() if the panel has been destroyed by your application. Here’s some code:
static class PersistentGLJPanel extends GLJPanel {
private boolean created;
private boolean destroyed;
public PersistentGLJPanel(GLCapabilities capabilities,
GLCapabilitiesChooser chooser,
GLContext shareWith) {
super(capabilities, chooser, shareWith);
}
public void addNotify() {
if (!created) {
created = true;
super.addNotify();
}
}
public void removeNotify() {
if (destroyed) {
super.removeNotify();
}
}
public void destroy() {
destroyed = true;
removeNotify();
}
}