Limit window maximum size

is there a way to set a maximum window size?

in particular I am trying to prevent content overflow by limiting the maximum window size

void setup() {
  // initial window size
  size(640, 360, P2D);

  // allow window to be resized
  surface.setResizable(true);
  
  view.setup(P2D);
  callOnSizeChanged(view, 720, 480);
  
  verticalScrollBar.onOverflow = verticalScrollBar.new OverflowRunnable() {
    @Override
    public void run(int value) {
      size(width, value, P2D);
    }
  };

  horizontalScrollBar.onOverflow = horizontalScrollBar.new OverflowRunnable() {
    @Override
    public void run(int value) {
      size(value, height, P2D);
    }
  };

  verticalScrollBar.setup(P2D);
  horizontalScrollBar.setup(P2D);

  verticalScrollBar.document = view;
  horizontalScrollBar.document = view;
}

but I get

When not using the PDE, size() can only be used inside settings().
Remove the size() method from setup(), and add the following:
public void settings() {
  size(720, 472, "processing.opengl.PGraphics2D");
}
IllegalStateException: size() cannot be used here, see https://processing.org/reference/size_.html

at

   horizontalScrollBar.onOverflow = horizontalScrollBar.new OverflowRunnable() {
     @Override
     public void run(int value) {
>      size(value, height, P2D);
     }
   };
if(width > maxW) surface.setSize(maxW,height);
if(height > maxH) surface.setSize(width,maxH);

I already tried that but it just glitches when resizing with mouse

In a previous code, I ran this in the beginning of draw() (this is for a minimum size, not a maximum, but the idea should be similar) :

GLWindow window = (GLWindow) getSurface().getNative();

final Dimension d = new Dimension(MIN_SIZE_X + 17, MIN_SIZE_Y + 40);

int xDist = max(window.getWidth(),  d.width )-window.getWidth ();
int yDist = max(window.getHeight(), d.height)-window.getHeight();

window.setSize(max(window.getWidth(), d.width), max(window.getHeight(), d.height));
window.setPosition(window.getLocationOnScreen(null).getX() - xDist, window.getLocationOnScreen(null).getY() - yDist);

And although this works, It is quite glichy… The thing is, anyone correct me if I’m wrong, but I don’t think that P2D PGraphics handle well resizing in general… it’s like the sketch stops when resizing, and no call to draw() is made…

Good luck !

wish there was a better way to set window size limits :frowning:

(and a way that actually works without having glitches such as the mouse overriding set size when resizable is true and the window is being resized)

just create an int wdth and hght (for width and height) and after you stop resizing the window, the variables are set to it. Because of that it won’t be buggy.