Hi,
Does anyone know how to lock a JFrame to resizing at a specific height-width ratio, specifically to maintain some ratio of a child component?
My setup right now: I have a JFrame in windowed mode with a menu bar and a JPanel in the content pane for rendering. (Asteroids clone). I’d like to make the JFrame resizable by the user, but I’d like to allow only sizes that keep the JPanel square.
So far, I can imagine trapping component resize events on the JFrame, doing some math in regards to figuring out how big the JFrame should be to make the JPanel square, and then posting setSize() on the JFrame.
Is there a better way to do it (with a layout manager, or something similar)? Something like trap resize events on the JPanel, set max and min size to that, and then will JFrame resize accordingly (perhaps with a call to pack())? Or is there some other interface which can be used to implement this?
Thanks,
Derek