Hello,
I’m trying to build a reusable OpenGL widget for Swing using a JPanel and a GLCanvas (to avoid perf of GLJPanel)
I have a problem to display the Swing popup menu on the surface display of the GLCanvas.
To illustrate this problem, I wrote a small test program:
import java.awt.BorderLayout;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
public class GLW extends JPanel{
private static final long serialVersionUID = 1L;
private GLWCanvas canvas;
private JPopupMenu popupmenu;
private JMenuItem jMenuItem0;
public GLW() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
this.setLayout(new BorderLayout());
this.setComponentPopupMenu(getJPopupMenu0());
this.add(getMixTestCanvas()); // ajout du widget hérité de GLCanvas
}
private GLWCanvas getMixTestCanvas(){
if (canvas == null) {
canvas = new GLWCanvas();
canvas.addGLEventListener(canvas);
}
return canvas;
}
private JPopupMenu getJPopupMenu0() {
if (popupmenu == null) {
popupmenu = new JPopupMenu();
popupmenu.add(getJMenuItem0());
}
return popupmenu;
}
private JMenuItem getJMenuItem0() {
if (jMenuItem0 == null) {
jMenuItem0 = new JMenuItem();
jMenuItem0.setText("jMenuItem0");
}
return jMenuItem0;
}
}
In this code the GLWCanvas is a class inherited from GLCanvas.
When I commented the line
this.add (getMixTestCanvas ());
The widget inherited from the widget GLCanvas is not displayed and the popup menu works fine. So far, everything is normal.
As against when I uncomment this line, the widget inherited from the widget GLCanvas is displayed (again, everything is normal), but the menu is not displayed (and here, it may be normal regarding my code, but it is not what I want!).
I tried to disable the lightweight nature of the JPanel with
JPopupMenu.setDefaultLightWeightPopupEnabled (false);
but it seems no effect. Does anyone have an idea for me to reach my purpose?
Thank you in advance.