The truth is that there is no direct way to remove the maximize button
off the JFrame as it is created by Windows and it is not painted using
Swing so U can’t touch this.
Still many posts on the net are giving “creative” suggestions on how to remove the maximze button of “JFrame”. The simplest and yet effective solution is to replace JFrame with JDialog as the latter does not have a maximize button. Other feasible “Java-based” solution is remove the title bar and painstakingly implement customized title bar.
Neutralizing the effect of maximization
The solution here neutralizes the effect of maximization and flashing a error message.
There are pros and cons to this approach. The pros is that it is still using JFrame and has minimise button (JDialog has no minimize button) and can be implemented quickly with few lines of code. The cons is that according to GUI guide rule, GUI component shouldn’t be displayed on screen if it doesn’t get used at all in under any circumstances, and beside the solution actually flash the screen as the JFrame maximize and get revert to previous size immediately.
Anyway, if JFrame is to be used and maximizing should prevented, the following does the trick.
- If maximize button clicked, the JFrame will maximize and then immediate revert back to previous size. Event is only fired after resizing not before, therefore there is no way to stop the resizing (eg ComponentListener, WindowListener). At the same time, a tooltip will be flashed just on the top right corner of the JFrame.
Video demonstration
The trick is the following code segment.
So when the frame is maximized, it will immediate revert back to “restore” size while at same time giving a beep and flashing a tooltip.
So here is the source code
File: MaximizeButtonDisabler.java (4kb) |







Comments
Jesse Sightler replied on Tue, 2009/07/21 - 3:43pm
GeekyCoder coder replied on Tue, 2009/07/21 - 9:34pm
Jesse Sightler,
setting setResizeable will work but JFrame will not be resizable anymore. My actual intent for this code is actually to create a Resizable JFrame that does not allow maximizing. I have omitted the Resizable word in my original post and have now updated it into blog post. thx
Dennis Müller replied on Wed, 2009/07/22 - 8:20am
Rael G.C. replied on Wed, 2009/07/22 - 2:51pm
GeekyCoder coder replied on Fri, 2009/07/24 - 10:37am
GeekyCoder coder replied on Fri, 2009/07/24 - 10:41am