Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable maximise in jFrame and resizeable using mouse

Tags:

java

swing

jframe

JFrame with hidden or no maximize button but should be able to re-size using mouse(clicking and dragging on jFrame border). setResizable(false) is only disabling the minimize button but not able to re-size using mouse.

like image 919
Abin Avatar asked Mar 11 '13 06:03

Abin


2 Answers

I personally can't think of a reason to allow resize and not allow maximize but here is an example of how to prevent maximizing a JFrame while still allowing resize and minimize. Tested in windows, untested on all other platforms. Full screen flash is minimized using setMaximizedBounds().

    final JFrame jFrameNoMax = new JFrame() {
        {
            setMaximizedBounds(new Rectangle(0, 0));
            addWindowStateListener(new WindowStateListener() {
                public void windowStateChanged(final WindowEvent e) {
                    if (e.getNewState() == MAXIMIZED_BOTH) {
                        setExtendedState(NORMAL);
                    }
                }
            });
        }
    };

    // Tester
    jFrameNoMax.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    jFrameNoMax.setSize(300, 300);
    jFrameNoMax.setLocation(300, 300);
    jFrameNoMax.setVisible(true);
like image 147
Java42 Avatar answered Oct 06 '22 00:10

Java42


You can take the following steps:

-Right click on JFrame -Select properties -Uncheck the resizable checkbox -Close properties -Run the program

See the attached illustration: Freeze maximize button

like image 44
Raymond Wachaga Avatar answered Oct 06 '22 01:10

Raymond Wachaga