1

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?

4

1 回答 1

4

似乎有问题LayoutManagerJPanelFlowLayout其用作默认值,将其更改为BorderLayout如下所示:

 JPanel panel = new JPanel(new BorderLayout());
于 2015-03-17T11:24:48.470 回答