ohoeppner
ohoeppner

Reputation: 173

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?

Upvotes: 0

Views: 1129

Answers (1)

alex2410
alex2410

Reputation: 10994

Seems problem with LayoutManager, JPanel use FlowLayout as default change it to BorderLayout like next:

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

Upvotes: 4

Related Questions