0

I have a glcanvas inside a jpanel with a BorderLayout. The size of the canvas should be dependent on the window size. The initial size is set via

glCanvas.setSize(640, 480);

And it is added to the panel like this

jPanel3DModel.add(Model3DCanvas.getInstance().getCanvas());
jPanelRight.add(jPanel3DModel, BorderLayout.NORTH);

However the size of the canvas is fixed and all the panels of the other components in my frame just resize.

  • BorderLayout.NORTH doesn't resize. Only BorderLayout.CENTER gets resized. You should use the GLJPanel, as the wiki suggests: https://jogamp.org/wiki/index.php/Using_JOGL_in_AWT_SWT_and_Swing#JOGL_in_Swing_using_the_GLJPanel – Sascha May 14 '19 at 11:34
  • Ok I put the canvas into the CENTER. The Panel resizes but not the canvas. –  May 14 '19 at 16:31
  • What you haven't explained is the ``jPanel3DModel`` component. Because you don't add the canvas directly to the ``jPanelRight``. Therefore the resizing is dependent on the resizing behavior of the ``jPanel3DModel`` component. – Sascha May 15 '19 at 08:49
  • Please provide a SSCCE. – gouessej May 15 '19 at 10:30

1 Answers1

0

If you have to react to the JPanel resize "manually", you can use a ComponentListener as described in https://docs.oracle.com/javase/tutorial/uiswing/events/componentlistener.html

Assuming canvas is your GLCanvas and jpanel the component your canvas resizing is depending on.

jPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
  public void componentResized(java.awt.event.ComponentEvent event) {
    int width=event.getComponent().getWidth();
    int height=event.getComponent().getHeight();
    canvas.setSize(width,height);
  }
});
Sascha
  • 1,320
  • 10
  • 16