开发者

Can I set a window in Java so it has uniform resizing (ie. a square)?

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.


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...


You should be able to modify the resize event handlers to increase both dimensions rather than just the one.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜