import net.java.games.jogl.*; import java.awt.*; import javax.swing.*; public class Test { public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel c = new JPanel(); c.setPreferredSize(new Dimension(400,400)); f.getContentPane().add(c); c.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = 1; gbc.weightx = gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; JPanel p = new JPanel(); p.setBackground(Color.RED); p.add(new JLabel("don't squeeze me!")); c.add(p,gbc); /* JPanel p2 = new JPanel(); p2.setBackground(Color.BLUE); p2.add(new JLabel("me neither!")); c.add(p2,gbc); */ GLCanvas glc = GLDrawableFactory.getFactory().createGLCanvas( new GLCapabilities()); glc.addGLEventListener( new GLEventListener() { public void init(GLDrawable drawable) {} public void display(GLDrawable drawable) { GL gl = drawable.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT); } public void displayChanged(GLDrawable d,boolean b,boolean c){} public void reshape(GLDrawable d,int a,int b,int c,int e){} } ); c.add(glc,gbc); // NOTE: the code below solves the problem // // JPanel cont = new JPanel(); // cont.setLayout(new BorderLayout()); // cont.add(glc, BorderLayout.CENTER); // cont.setPreferredSize(new Dimension(0, 0)); // c.add(cont, gbc); f.pack(); f.setVisible(true); } }