code: private void setParentMaximum(boolean maximize) {
          if (rootParent instanceof JFrame) {
              JFrame frame = (JFrame) rootParent;
              int    state = frame.getExtendedState();
  
              if (maximize) {
                  GraphicsConfiguration gc = frame.getGraphicsConfiguration();
                  Insets                i  = Toolkit.getDefaultToolkit().getScreenInsets(gc);
                  Rectangle             r  = gc.getBounds();
  
                  r.x      = 0;
                  r.y      = 0;
                  r.width  -= i.left + i.right;
                  r.height -= i.top + i.bottom;
                  frame.setMaximizedBounds(r);
              }
  
              frame.setExtendedState(maximize ? state | Frame.MAXIMIZED_BOTH : state & ~Frame.MAXIMIZED_BOTH);
          }
      }
docs: Maximize/Restore the window.
  
  @param maximize iconify {@code true} if we are to maximize the window,
  {@code false} if we are to restore the window.