0

So, I have a JFrame. Nothing special about it, besides:

this.setResizable(false);

I do this, because I do not want the user to change the size of the window during its normal (non-maximized non-minimized) state.

However, I still want the user to be able to maximize the JFrame, but that line of code not only disables the possibility of re-sizing the window with the mouse, but also the possibility of re-sizing with the maximize button, since it gets locked.

(Possible solutions I see are either enabling the maximize button after I set the resizability to false, or preventing the mouse from resizing the window, without using the line above)

So, how do I prevent the user from resizing my window manually while still being able to maximize it?

RaKXeR
  • 152
  • 2
  • 16
  • 1
    *"I do not want the user to change the size of the window during its normal (non-maximized non-minimized) state."* Why? And why does your desire for me (an hypothetical end user of the software) not to resize a window that appears on *my* computer screen override my desire to do whatever the heck I please with my window on my screen? See [What is the XY problem?](http://meta.stackexchange.com/q/66377) – Andrew Thompson Apr 09 '16 at 14:32
  • @AndrewThompson I modified the end of the question to avoid confusion. Now, hypothetical end user of the software, you see, when I manually resized my window in testing, it looked incredibly glitchy, which is something I would like my users not to encounter. And I find that it is better to give the user the possibility to maximize the window if he thinks it is too small (or too big if their screen has the size of a pea), instead of forcing him to look at the window with that size. Also, hypothetical user, if you don't like my designer choice, the close button is alive and well. – RaKXeR Apr 09 '16 at 14:41
  • 1
    *"..when I manually resized my window in testing, it looked incredibly glitchy.."* **That** is what needs fixing. This approach is a hack (& an irritating one, if it is achieved) to cover a bug. – Andrew Thompson Apr 09 '16 at 14:44
  • @AndrewThompson it looks "glitchy" because java swing is slow af, and no matter what I do it will flash every time I resize, unless I completely abandon swing, which I do not have time to do. Either way, what I asked is what I want to know, and not what you think I should have asked. – RaKXeR Apr 09 '16 at 14:47
  • 1
    `when I manually resized my window in testing, it looked incredibly glitchy` - probably a problem in your layout code or somewhere else. Given that in your last question you are using a MouseListener to invoke a menu item, who knows what other strange things you might be doing. However, you could use the Toolkit class to disable dynamic layout. Then the layout will only be painted when you release the mouse. As you are dragging the frame only the border of the frame will change. As a user I wouldn't like that. I have never had a problem with Swing resizing. – camickr Apr 09 '16 at 15:09
  • guys, I think you are the ones with the XY problem. OK, I will do a bit more digging into why it looks weird when I re-size it. However, I still want an answer to the question this post is about. – RaKXeR Apr 09 '16 at 15:11

0 Answers0