Currently I have a menu bar attached to the main frame and a GLJPanel inside of a JInternalFrame. When I use the menu bar and it drops down, the GLJPanel’s contents are drawn over the drop down menu. Has anyone had this problem before?
To make JMenus work over a GLCanvas I used [b]JPopupMenu.setDefaultLightWeightPopupEnabled(false);[/b]
. Perhaps this will help with your problem.
I tried putting JPopupMenu.setDefaultLightWeightPopupEnabled(false); in several locations in my code, and the problem still exists.
thanks anyway.
It’s pretty ugly but is that what you are/where trying to achieve?
test.java
import java.awt.*;
import javax.swing.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;
public class test{
public static void main(String args[]){
SwingUtilities.invokeLater(new Runnable(){
public void run(){
new test();
}
});
}
test(){
JFrame frame = new JFrame("hello");
frame.setLayout(null);
frame.setSize(400, 400);
JInternalFrame intframe = new JInternalFrame("hello", true, true, true, true);
intframe.setBounds(0, 0, 150, 150);
GLJPanel panel = new GLJPanel();
intframe.add(panel);
final FPSAnimator animator = new FPSAnimator(panel, 80);
panel.addGLEventListener(new testRenderer());
JMenuBar jmb = new JMenuBar();
JMenu jmFile = new JMenu("File");
JMenuItem open = new JMenuItem("Open");
JMenuItem close = new JMenuItem("Close");
JMenuItem test = new JMenuItem("test");
jmFile.add(open);
jmFile.add(close);
jmFile.add(test);
jmb.add(jmFile);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(jmb);
frame.add(intframe);
intframe.setVisible(true);
frame.setVisible(true);
}
}
testRenderer.java
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
public class testRenderer implements GLEventListener{
private float hdri;
private float hvie;
public void init(GLAutoDrawable drawable){
final GL gl = drawable.getGL();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
drawable.addKeyListener(new KeyAdapter(){
public void keyPressed(KeyEvent e){
if(e.getKeyCode() == KeyEvent.VK_ESCAPE){
System.exit(0);
}
}
});
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height){
final GL gl = drawable.getGL();
final GLU glu = new GLU();
if (height <= 0)
height = 1;
final float h = (float)width / (float)height;
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0f, 20.0f);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}
public void display(GLAutoDrawable drawable){
final GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(-1.5f, 0.0f, -6.0f);
gl.glRotatef(hdri,0.0f,1.0f,0.0f);
gl.glBegin(GL.GL_TRIANGLES);
gl.glColor3f(1.0f, 0.0f, 0.0f);
gl.glVertex3f( 0.0f, 1.0f, 0.0f);
gl.glColor3f(0.0f, 1.0f, 0.0f);
gl.glVertex3f(-1.0f,-1.0f, 0.0f);
gl.glColor3f(0.0f, 0.0f, 1.0f);
gl.glVertex3f( 1.0f,-1.0f, 0.0f);
gl.glEnd();
gl.glLoadIdentity();
gl.glTranslatef(1.5f, 0.0f, -6.0f);
gl.glRotatef(hvie,1.0f,0.0f,0.0f);
gl.glColor3f(0.5f,0.5f,1.0f);
gl.glBegin(GL.GL_QUADS);
gl.glVertex3f(-1.0f, 1.0f, 0.0f);
gl.glVertex3f( 1.0f, 1.0f, 0.0f);
gl.glVertex3f( 1.0f,-1.0f, 0.0f);
gl.glVertex3f(-1.0f,-1.0f, 0.0f);
gl.glEnd();
hdri+=0.20f;
hvie-=0.15f;
}
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged){
}
}