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