Mac exception on "frame.add( canvas )"

Porting a working Jogl program (equivalent to the “gears” demo) to my new Mac using Eclipse, compiles OK, but I get an exception at run-time indicating its improper to add my glcanvas to a frame and advises I should add the glcanvas to the frame’s content pane. While this may be correct using a standard setup, is there a workaround? Has anyone run into this problem? Seem to be inherent in the JVM.

Tried running from Eclipse and command line - got same results.

I’m new to the Mac and Eclipse (I’ve been using NetBeans on Windows and Linux) so, it may be cockpit error.

It’s the common way of doing this with jdk 1.4 or less (on any os).

frame.add(X) => frame.getContentPane().add(X);

If you plan to develop for 1.5(Win/Linux) and 1.4(Mac), you’ll have to stick to the old api, on override add() on your subclass of JFrame.

Lilian

If you used a Frame it should work fine. If you’re using a JFrame you have to add it to the contentpane. (myJFrame.getContentPane.add(canvas)) :slight_smile:

I did get it to run by adding to the contentPane, however the results were a little odd. At that point, I was probably had the wrong frame type. I’ll try at home again tonight, if I can get througn XCode, Eclipse, Finder, OsX, AppleScript, etc. overload.

Thanks

As pointed out above, You’re probably trying to add a GLCanvas to a JFrame. This is ill-advised, Use a Frame instead of a JFrame, and just use frame.add(canvas) and it ought to work just fine. JFrame is a Swing component that overrides Frame and adds in the contentpane which is a lightweight component. GLCanvas is a heavyweight AWT component that doesn’t really play nice with the lightweight swing stuff.

As an example, heres how I do it, works with no problems.


GLCapabilities desiredCaps = new GLCapabilities();
desiredCaps.setDepthBits(24);
        
canvas = GLDrawableFactory.getFactory().createGLCanvas(desiredCaps);
canvas.setGL(new DebugGL(canvas.getGL()));
frame = new Frame();
frame.setLayout(new BorderLayout());
frame.add(canvas, BorderLayout.CENTER);

D.

is there a way to work with swing/jogl?
iv read that the jglpanel or however its named isnt hardwareaccelerated… and i wanted to make a jtabbed pane for a game… with one tab für the gl part of the game and the other ones for the main menue and such stuff
till now i thought i can easiely put my glcanvas onto the jtabbedpane cause its supposed to be on the top so i thought it makes no difference if i use the heavywight canvas :confused:

I stuff my GLPanel in a JLabel and then inside a tabbed pane. Works like a charm. And all this inside a JFrame :slight_smile:

lol why in a jlabel??
i thought we’r supposed to use glcanvas not glpanel couse i dont know :wink:
nah there is something in my mind about glpanel not accelerated or something

Otherwise I get all kind of nasty crashes when integrating the GLCanvas inside my other swing components.

i just tryed a jframe->jpanel->glcanvas
and is seemed to work (not a big test i know im lazie :wink:
however if i use gljpanel it gets damn slow…

and that nasty heavywight thing… but there is no way around or?