Java - Lock Aspect Ratio of JFrame
Posted
by nasufara
on Stack Overflow
See other posts from Stack Overflow
or by nasufara
Published on 2010-03-23T00:37:56Z
Indexed on
2010/03/23
0:41 UTC
Read the original article
Hit count: 617
Is it possible to lock the aspect ratio of a JFrame in Java Swing?
For example, if my window is 200px by 200px, and the user wants to resize it, I want the ratio between the width and the height at 1:1, so that if the new width is 400px, the new height is forced to 400px.
I'm aware of ComponentListener
and componentResized
, but I'm having difficulty not getting it to go into an infinite loop of resizing, because I'm resizing the window in a resize listener.
Thanks!
© Stack Overflow or respective owner