How to maintain the proportions of a component?
843806May 13 2009 — edited Nov 22 2009The root content pane of my swing application has a third-party JComponent (A PCanvas from Piccolo http://www.piccolo2d.org) in the center position of a border layout. The objects I'm displaying inside this PCanvas have a fixed proportion. A problem comes when the user resizes the window and changes its proportions, the objects in my PCanvas no longer fit into the shape of the PCanvas, and I get some ugly background colour showing through at the edges.
It is a lot like displaying a 1024*768 image file in an image viewer. The image can be shown with the right proportions in windows of 1280*1024, 1024*768, 800*600, 640*480 etc. But if the shape of the proportions of the window (height vs width) change there has to be some empty space in the window or you have to stretch the image.
Is it possible to restrict the user's ability to resize a window so that they must maintain the proportions of the window?
Or is it possible to have swing maintain the proportions of my PCanvas component when the window resizes, and just show a swing grey background in the gaps that appear?