import javax.media.opengl.*; import java.awt.*; import javax.swing.*; public class ResizeIssue { public static void main(String[] args) { JFrame frame = new JFrame("Resize Issue"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setPreferredSize(new Dimension(400,400)); frame.getContentPane().add(panel); panel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = 1; gbc.weightx = gbc.weighty = 1; gbc.fill = GridBagConstraints.BOTH; JPanel redPanel = new JPanel(); redPanel.setBackground(Color.RED); redPanel.add(new JLabel("don't squeeze me!")); panel.add(redPanel,gbc); final GLCanvas canvas = new GLCanvas(); // Make the canvas clear itself when drawn canvas.addGLEventListener(new GLEventListener() { public void init(GLAutoDrawable drawable) { drawable.getGL().glClearColor(0.3f, 0.3f, 0.3f, 1.0f); } public void display(GLAutoDrawable drawable) { drawable.getGL().glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {} public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {} }); panel.add(canvas,gbc); // NOTE: the code below solves the problem for Java >= 1.5 // canvas.setPreferredSize(new Dimension(0,0)); // NOTE: the code below solves the problem for Java < 1.5 // JPanel cont = new JPanel(); // cont.setLayout(new BorderLayout()); // cont.add(canvas, BorderLayout.CENTER); // cont.setPreferredSize(new Dimension(0, 0)); // c.add(cont, gbc); frame.pack(); frame.setVisible(true); } }