9

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.

Apurv
  • 3,723
  • 3
  • 30
  • 51
Abin
  • 540
  • 4
  • 15

3 Answers3

2

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);
Java42
  • 7,628
  • 1
  • 32
  • 50
2

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

Wachaga Mwaura
  • 3,310
  • 3
  • 28
  • 31
0

One option could be to use a JDialog instead of a JFrame. This allows the window to be manually resizeable but not maximizeable. The only problem with doing this is that you lose both the minimize and maximize buttons. This may or may not be a problem for your application.

Breavyn
  • 2,232
  • 16
  • 29