Reputation:
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.
Upvotes: 0
Views: 457
Reputation: 1343
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);
}
});
Upvotes: 0