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.
- Is this a bug in anything on Apple’s side?
- Is this a bug in Jogl?
- Is this a bug in this app (using GLCanvas in JFrame)?
- 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