Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you prevent a maximize?  RSS feed

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I have an application (Swing based) without a title bar, but the user can still maximize by going to the Windows Task Manager, selecting the application, right clicking, and then clicking on maximize.

Well, I have been asked to prevent this. No problem I thought...just do a this.setResizeable(false) in the JFrame...WRONG! It still mazimizes just fine.

Then I thought that maybe I could catch and ignore the maximize event using the this.enableEvents(AWTEvent...), but I found no such event to ignore.

So....is there any way to ignore the maximize event?

THANKS!
 
Lionel Badiou
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Darrin,

1- Are you certain that it will be valuable for your users to get an application that behave diffently for any others (unresizeable app)? The answer may be yes, but you should think about it carefuly

2- Fixing dimensions is rarely a good idea once you consider internationalization.

2- To solve your problem, you may manage manually the repainting of your application (paintComponent()) into dimension you want.

Hope that helps,
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answers:

1) REQUIREMENT...not my call!
2) No need to worry about that...in house thing.
3) I was afraid you would say that.

To me, there should be a way to trap maximize/minimize events coming to Java apps. This is an oversight imho.

Thanks for the feedback though!


Originally posted by Lionel Badiou:
Hello Darrin,

1- Are you certain that it will be valuable for your users to get an application that behave diffently for any others (unresizeable app)? The answer may be yes, but you should think about it carefuly

2- Fixing dimensions is rarely a good idea once you consider internationalization.

2- To solve your problem, you may manage manually the repainting of your application (paintComponent()) into dimension you want.

Hope that helps,
 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, I believe there is a way to stop this. You might get some flickering (them seeing it maximize for a second), but you can pop up an alert box and reset the size to what it was.

Add a window listener (or check it's state) and when maximize is called, simply un-maximize and resize it to regular size.

Here's the code (unfortunately, I don't know how to grab the attamept at changing the state so it won't maximize for a second first):

 
Dan Bizman
Ranch Hand
Posts: 387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, what am I thinking? Scratch all that above wasted code and just call:

frame.setResizable( false );

and they won't be able to resize it, even from the task bar!
 
Mousa A. Rafi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darrin Smith:
If you used JFrame for that, you might want to use JWindow. It has no title bar, and is not resizable, minimizable, maximizable, or closable.
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dan, but I tried this first thing (thought that it would work just like you did)...it didn't!

The maximize comining in from Windows Task Manager must not be treated as a typcial resize.

Originally posted by Dan Bizman:
Actually, what am I thinking? Scratch all that above wasted code and just call:

frame.setResizable( false );

and they won't be able to resize it, even from the task bar!
 
Daniel Searson
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JWindow would be much nicer from the sounds of things. Its pretty much exactly the same as a JFrame but with no title bar (that you don't have anyway) and it doesn't have resizing controls.

One downside is that I'm pretty sure it won't show up in the task bar at all, which may or may not be a problem for you.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setMaximizedBounds(new Rectangle(100,100,350,300));

seems to work OK
 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That does work.

The only thing is, now the application (still not maximized...correct size) gets redrawn at the very top of the screen!

Originally posted by Michael Dunn:
setMaximizedBounds(new Rectangle(100,100,350,300));

seems to work OK
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your actual code would be something like this

setMaximizedBounds(new Rectangle(frame.getX(),frame.getY(),frame.getWidth(),frame.getHeight()));

you may not need the frame. references, depending on your code structure.
I think it would have to be set after being visible, for the getX() and getY() to work

or you could just hard-code in your setSize() and setLocation() numbers
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!