0

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?

ohoeppner
  • 173
  • 3
  • 10
  • 2
    This isn't actually surprising. `GLCanvas` is based directly off `java.awt.Canvas`. Mixing heavy weight containers within light containers always results in weird issues, mostly relating to the z-ordering of the components (AWT components have no concept of z-ordering). While I know that was "suppose" to be fixed in Java 6, I've witnessed to many "weird" issues around it to consider using it. Best bet, don't mix heavy and lightweight components – MadProgrammer Mar 17 '15 at 11:55

1 Answers1

4

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

 JPanel panel = new JPanel(new BorderLayout());
alex2410
  • 10,904
  • 3
  • 25
  • 41