GLCanvas in JFrame on OSX?

I know you’re not supposed to mix lightweight and heavyweight components. But on Windows we’ve not had any problem with our viewer (extends a Panel and contains GLCanvas) in a JFrame and with a JPanel next to it in the BorderContainer.

On OSX, the GLCanvas reports its width and height as we’d expect, but the JPanel next to it gets covered up.

We made a simple testapp. The behavior for this is different between Windows and Mac OSX.

  1. Is this a bug in anything on Apple’s side?
  2. Is this a bug in Jogl?
  3. Is this a bug in this app (using GLCanvas in JFrame)?
  4. Is this some other simple bug that I’m just missing?

Here is the code for a simple testapp that reproduces it.



import net.java.games.jogl.*;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

public class test extends JFrame implements GLEventListener {
    private JButton _button;

    public test () {
        getContentPane().setLayout(new BorderLayout());
        setTitle("Using GLCanvas in JPanel");
        setSize(850, 500);

            // Border layout panel
        JPanel mainPanel = new JPanel(new BorderLayout(3, 3));
        mainPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        getContentPane().add(mainPanel, BorderLayout.CENTER);

            // UI panel
        JPanel controlPanel = setupInterface();
        mainPanel.add(controlPanel, BorderLayout.EAST);

        GLCanvas canvas = GLDrawableFactory.getFactory().createGLCanvas(new GLCapabilities());        
        canvas.addGLEventListener(this);
        mainPanel.add(canvas, BorderLayout.CENTER);
    }

    public void init(GLDrawable drawable) {}
    
    public void displayChanged(GLDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
    
    public void reshape(GLDrawable drawable, int x, int y, int width, int height) {}


    public void display(GLDrawable drawable) {
        GLCanvas canvas = (GLCanvas) drawable;
    
        GL gl = canvas.getGL();
        
        gl.glClearColor(0.f,0.5f,1.f,1.f);
        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
              
        gl.glPushMatrix();
        gl.glOrtho(-1.f,1.f,-1.f,1.f,-1.f,1.f);
        
        gl.glColor3f(1.0f, 1.0f, 0.0f);
        gl.glBegin(GL.GL_TRIANGLES);
        float _x = 0.0f, _y = 0.0f;
        gl.glVertex3f(_x + -0.5f, _y + -0.5f, 0.0f);
        gl.glVertex3f(_x +  0.5f, _y + -0.5f, 0.0f);
        gl.glVertex3f(_x +  0.0f, _y +  0.5f, 0.0f);
        gl.glEnd();
        
        gl.glPopMatrix();
    }
    
    private JPanel setupInterface () {
        // The main UI panel will use a GridBagLayout with two columns.
        JPanel panel = new JPanel(new GridBagLayout());
        panel.setPreferredSize(new Dimension(400, 500));
        panel.setBorder(new EtchedBorder());

        _button = new JButton("Press Me!");
        panel.add(_button);
        return panel;
    }


    public static void main (String[] args) {
        test app = new test();
        app.setVisible(true);
    }
}

thanks
andy

I had a similar problem on windows once, but I was trying to do something like have a heavyweight in a scrollpane. I nested one heavyweight within another to solve it. The outer heavyweight clipped the nested one. I don’t think this issue is quite like mine… but maybe nesting components can be used as a workaround.

Thanks. A coworker tried nesting this one in different ways, and couldn’t get it to work.

I’d really like to know why this works on Windows and not on the Mac.

thanks
andy

By the way, we’re using OSX 10.2, and Java 1.4.1.

andy

10.2.?
Do you have Update 1 to Java 1.4.1 ?

The native implementations are really very different both for Swing and for LWJGL with respect to different platforms especially when it comes to what you’re doing which is an offshoot of evil that will cause you significant problems. Part of this will be resolved when you get to 10.3 or 1.4.2 on OSX. As a general rule putting a heavyweight component next to a lightweight component in the same lightweight container will have ‘interesting’ behavior depending on the behavior of the heavyweight component.

You can post the issue to Apple, but I’m sure they’ll say ‘don’t do that’ because really you shouldn’t. A heavyweight component will always overlay a lightweight one. In OSX all of the rendering happens in the NSView that we get back from the native peer (the canvas) so if there is any issue - it would be at the window manager level.

Thanks, I think you’re right. Our product itself doesn’t mix the two, but we do have an example appliation that does (and normally works). We probably ought to change the example, to not encourage that practice.

thanks,
andy