Java swing JPanel示例,GLCanvas错误

时间:2015-04-13 07:28:35

标签: swing opengl jpanel jogl glcanvas

public class Activator implements BundleActivator {

TestFrame testFrame = new TestFrame();

public static JPanel graphPanel;

public void start(BundleContext context) throws Exception {


        graphPanel = cartesianGraphs.getGraphPanel();


        testFrame.getPanel1().add(graphPanel);

        testFrame.setVisible(true);
    } 
}



public class TestFrame extends JFrame {

private static final long serialVersionUID = 1L;

private library kutuphane = null;

private JPanel contentPane;
private JTabbedPane tabbedPane;
private JPanel panel1;
private JButton btn;


public TestFrame() {
    initComponents();
}

private void initComponents() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 800, 600);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);
    contentPane.add(getTabbedPane(), BorderLayout.CENTER);
    contentPane.add(getBtn(), BorderLayout.NORTH);
}



public JPanel getPanel1() {
    if (panel1 == null) {
        panel1 = new JPanel();
        panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
    }
    return panel1;
}

private JButton getBtn() {
    if (btn == null) {
        btn = new JButton("Remove All and Add");
        btnTabSil.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {


                TestFrame.this.getPanel1().removeAll();
                Activator.graphPanel.revalidate();

                 // where it throws the exception is below
                TestFrame.this.getPanel1().add(Activator.graphPanel);
                TestFrame.this.revalidate();
                TestFrame.this.repaint();
                TestFrame.this.setVisible(true);
            }
        });
    }
    return btn;
}

}

在上面的激活器类中,我将(JPanel) graphpanel 添加到(JPannel) testFrame.getPanel1()然后使用我在testFrame类中使用的按钮 removeAll()方法并再次添加静态graphPannel,但我收到了以下错误。

当我调试它时,我看到 GLcanvas失去了同伴。我无法找到解决方案。

  

线程“Thread-3”中的异常java.lang.RuntimeException:   javax.media.opengl.GLException:无法创建临时OpenGL上下文   对于设备上下文0xffffffffde01148b at   jogamp.common.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)at at   jogamp.opengl.awt.AWTThreadingPlugin.invokeOnOpenGLThread(AWTThreadingPlugin.java:103)     在   jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:205)     在   javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)     在javax.media.opengl.Threading.invoke(Threading.java:191)at   javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:449)at at   grafik.view.grafik.Gcontroller.draw(Gcontroller.java:169)at   grafik.model.data.Dcontroller.drawAll(Dcontroller.java:272)at   grafik.view.Wcontroller.GdataClean(Wcontroller.java:261)at   grafik.view.WThread.run(WThread.java:57)引起:   javax.media.opengl.GLException:无法创建临时OpenGL上下文   对于设备上下文0xffffffffde01148b at   jogamp.opengl.windows.wgl.WindowsWGLContext.createImpl(WindowsWGLContext.java:306)     在   jogamp.opengl.GLContextImpl.makeCurrentWithinLock(GLContextImpl.java:572)     在jogamp.opengl.GLContextImpl.makeCurrent(GLContextImpl.java:485)     在   jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:645)     在jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:594)     在javax.media.opengl.awt.GLCanvas $ 8.run(GLCanvas.java:996)at   java.awt.event.InvocationEvent.dispatch(未知来源)at   java.awt.EventQueue.dispatchEventImpl(未知来源)at   java.awt.EventQueue.access $ 300(未知来源)at   java.awt.EventQueue $ 3.run(未知来源)at   java.awt.EventQueue $ 3.run(未知来源)at   java.security.AccessController.doPrivileged(Native Method)at   java.security.ProtectionDomain $ 1.doIntersectionPrivilege(未知   来自)java.awt.EventQueue.dispatchEvent(未知来源)at   java.awt.EventDispatchThread.pumpOneEventForFilters(未知来源)     at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)     在java.awt.EventDispatchThread.pumpEventsForHierarchy(未知   来自java.awt.EventDispatchThread.pumpEvents(未知来源)     at java.awt.EventDispatchThread.pumpEvents(Unknown Source)at   java.awt.EventDispatchThread.run(未知来源)

1 个答案:

答案 0 :(得分:1)

请切换到JOGL 2.3.1。然后,替换" javax.media" by" com.jogamp"避免任何编译错误。

当您从其父容器中删除AWT GLCanvas时,它会丢失其对等体并且其OpenGL上下文被销毁。这是使用这种画布时无法避免的。如果这不是所需的行为,请切换到NEWT。

在某些硬件上,某些特定情况下创建另一个上下文可能会失败。如果您仍然使用最新版本的JOGL获得相同的堆栈跟踪,请填写错误报告:http://jogamp.org/wiki/index.php/Jogl_FAQ#Bugreports_.26_Testing