简体   繁体   中英

GLCanvas inside JPanel doesn't work

I am trying to add a GLCanvas with OpenGL-Content to a JPanel. The JPanel is inside a JTabbedPane. But when the GLCanvas is inside the JPanel, the Panel is just grey. When I add the GLCanvas directly into the TabbedPane, everything works fine.

XXX

Here the working code:

    JTabbedPane mainPane = frame.getMainPane();
    GLCanvas canvas = cogl.getCanvas();
    mainPane.add("OGL",canvas);

An here is the not-working code:

    JTabbedPane mainPane = frame.getMainPane();
    GLCanvas canvas = cogl.getCanvas();

    JPanel panel = new JPanel();
    panel.add(canvas);

    mainPane.add("OGL",panel);

So how can i get the GLCanvas working inside the JPanel?

似乎LayoutManager出现问题, JPanel使用FlowLayout作为默认值,将其更改为BorderLayout如下所示:

 JPanel panel = new JPanel(new BorderLayout());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM