I've seen several applications window's only allow the user to resize it in the diagonal direction, so it must maintain its square shape.
Is it possible to specify this constrain using swing/java?
I've seen several applications window's only allow the user to resize it in the diagonal direction, so it must maintain its square shape.
Is it possible to specify this constrain using swing/java?
I haven't heard of anything built in to do that. You could add a componentListener and from the resize events in that trigger resizes of the window to keep it square.
You should be able to modify the resize event handlers to increase both dimensions rather than just the one.
Personally, I would attach a ComponentListener
to the window and in the componentResized
method check the new window size and set the width equal to the height or vice versa.
Probably not the most efficient way though...
Resizing of a JFrame is handled by the OS, so it will be difficult to control unless you use a ComponentListener as suggested by all the other answers.
However, if you are talking about a JWindow, then resizing is NOT supported automatically and you need to provide support for this. Resizing Components entry might help you get started. I think you would need to make two changes:
a) limit the dragging to the diagonals b) change the "drag distance" to be the maximum of the width/height drag distance and use that value for both future calculations.
Since I don't know if this is your real requirement, I won't go into any more detail.