# Set Window's Minimum size when using P2D

**URL:** https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192
**Category:** Coding Questions
**Created:** [June 23, 2018, 11:44pm UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192 "2018-06-23T23:44:11Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![VansiusProductions](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@VansiusProductions](https://discourse.processing.org/u/VansiusProductions)
#### Post date: [June 23, 2018, 11:44pm UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/1 "2018-06-23T23:44:11Z")

</div>

Hi,

How do i Set Window’s Minimum size when using the P2D renderer? I know for the default Java renderer I would do this:

```auto
PSurfaceAWT.SmoothCanvas sc = (PSurfaceAWT.SmoothCanvas) getSurface().getNative();
JFrame jf = (JFrame) sc.getFrame();
jf.setMinimumSize(new Dimension(1600, 900));

```

But the code above will not work when I use the P2D renderer. What will I need to do in this case? Any help would be appreciated!

---

<div class="post-metadata">

### Author: ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)
#### Post date: [June 23, 2018, 11:57pm UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/2 "2018-06-23T23:57:12Z")

</div>

I don’t know how to do this off the top of my head, but if I were trying to figure it out I would take a look at the error message you’re getting: they’ll tell you the classes that are actually being used. I’d also look through the [Processing source code](https://github.com/processing/processing) to see what’s going on inside the P2D renderer to know how to get to the underlying window.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 24, 2018, 12:10am UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/3 "2018-06-24T00:10:19Z")

</div>

Dunno either! But you should start your search here methinks: 🙄  
[https://JogAmp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/newt/Window.html](https://JogAmp.org/deployment/jogamp-next/javadoc/jogl/javadoc/com/jogamp/newt/Window.html)

```auto
import com.jogamp.newt.Window;
Window window;

void setup() {
  size(800, 600, P2D);
  window = (Window) getSurface().getNative();
  println(window);
}

```

---

<div class="post-metadata">

### Author: ![VansiusProductions](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@VansiusProductions](https://discourse.processing.org/u/VansiusProductions)
#### Post date: [June 24, 2018, 1:04am UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/4 "2018-06-24T01:04:19Z")

</div>

Thanks for the useful link. I wrote a few lines of code to test this but I can’t even resize the windows itself. In my code I already did surface.setResizable(true). Doing window.setResizable(true) gives me the following error:

```auto
RunnableTask.run(): A caught exception occured on thread main-Display-.windows_nil-1-EDT-1: RunnableTask[enqueued true[executed false, flushed false], tTotal 0 ms, tExec 0 ms, tQueue 0 ms, attachment null, throwable java.lang.RuntimeException: Waited 5000ms for: <61a7904a, 55421619>[count 3, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.windows_nil-1-EDT-1>]
java.lang.RuntimeException: Waited 5000ms for: <61a7904a, 55421619>[count 3, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.windows_nil-1-EDT-1>
	at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
	at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2118)
	at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:450)
	at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2782)
	at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2154)
	at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:370)
	at processing.opengl.PSurfaceJOGL$5.run(PSurfaceJOGL.java:452)
	at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:127)
	at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:375)
DefaultEDT.run(): Caught exception occured on thread main-Display-.windows_nil-1-EDT-1: RunnableTask[enqueued false[executed true, flushed false], tTotal 5001 ms, tExec 5001 ms, tQueue 0 ms, attachment null, throwable java.lang.RuntimeException: Waited 5000ms for: <61a7904a, 55421619>[count 3, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.windows_nil-1-EDT-1>]
java.lang.RuntimeException: Waited 5000ms for: <61a7904a, 55421619>[count 3, qsz 0, owner <main-FPSAWTAnimator#00-Timer0>] - <main-Display-.windows_nil-1-EDT-1>
	at jogamp.common.util.locks.RecursiveLockImpl01Unfairish.lock(RecursiveLockImpl01Unfairish.java:198)
	at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2118)
	at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:450)
	at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2782)
	at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2154)
	at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:370)
	at processing.opengl.PSurfaceJOGL$5.run(PSurfaceJOGL.java:452)
	at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:127)
	at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:375)
handleDraw() called before finishing
com.jogamp.opengl.GLException: Caught ThreadDeath: null on thread main-FPSAWTAnimator#00-Timer0
	at com.jogamp.opengl.GLException.newGLException(GLException.java:76)
	at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1327)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
	at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
	at jogamp.opengl.GLAutoDrawableBase.defaultWindowResizedOp(GLAutoDrawableBase.java:260)
	at com.jogamp.newt.opengl.GLWindow.access$200(GLWindow.java:119)
	at com.jogamp.newt.opengl.GLWindow$2.windowResized(GLWindow.java:141)
	at jogamp.newt.WindowImpl.consumeWindowEvent(WindowImpl.java:4383)
	at jogamp.newt.WindowImpl.sendWindowEvent(WindowImpl.java:4317)
	at jogamp.newt.WindowImpl$ResizableAction.run(WindowImpl.java:2137)
	at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:2780)
	at jogamp.newt.WindowImpl.setResizable(WindowImpl.java:2154)
	at com.jogamp.newt.opengl.GLWindow.setResizable(GLWindow.java:370)
	at mypackage.Game.setup(Game.java:268)
	at processing.core.PApplet.handleDraw(PApplet.java:2412)
	at processing.opengl.PSurfaceJOGL$DrawListener.display(PSurfaceJOGL.java:859)
	at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:692)
	at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:674)
	at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:443)
	at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1293)
	at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:1147)
	at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:759)
	at com.jogamp.opengl.util.AWTAnimatorImpl.display(AWTAnimatorImpl.java:81)
	at com.jogamp.opengl.util.AnimatorBase.display(AnimatorBase.java:452)
	at com.jogamp.opengl.util.FPSAnimator$MainTask.run(FPSAnimator.java:178)
	at java.util.TimerThread.mainLoop(Timer.java:555)
	at java.util.TimerThread.run(Timer.java:505)
Caused by: java.lang.ThreadDeath
	at java.lang.Thread.stop(Thread.java:853)
	at com.jogamp.newt.opengl.GLWindow$GLLifecycleHook$1.run(GLWindow.java:724)
	at java.security.AccessController.doPrivileged(Native Method)
	at com.jogamp.newt.opengl.GLWindow$GLLifecycleHook.shutdownRenderingAction(GLWindow.java:719)
	at jogamp.newt.WindowImpl.shutdown(WindowImpl.java:635)
	at jogamp.newt.WindowImpl.shutdownAll(WindowImpl.java:123)
	at jogamp.newt.DisplayImpl$1.run(DisplayImpl.java:74)
	at com.jogamp.nativewindow.NativeWindowFactory.shutdown(NativeWindowFactory.java:272)
	at com.jogamp.nativewindow.NativeWindowFactory$2$1.run(NativeWindowFactory.java:190)
	at java.lang.Thread.run(Thread.java:748)

```

I don’t know what is happening here 😐.

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [June 24, 2018, 1:14am UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/5 "2018-06-24T01:14:34Z")

</div>

> [@VansiusProductions](#):
>
> … but I can’t even resize the windows itself.

According to your original post: 🙄

> [@VansiusProductions](#):
>
> How do i set window’s minimum size when using the P2D renderer?

You’ve seemed interested in setting minimum size only, not programmatically resizing the window directly! 😵

If it is just the latter now, the class PSurface already got a **setSize()** method: 🕶  
`getSurface().setSize(width>>1, height>>1);`

---

<div class="post-metadata">

### Author: ![VansiusProductions](https://avatars.discourse-cdn.com/v4/letter/v/4da419/32.png) [@VansiusProductions](https://discourse.processing.org/u/VansiusProductions)
#### Post date: [June 24, 2018, 1:16am UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/6 "2018-06-24T01:16:22Z")

</div>

Oh, I meant resizing the window manually, not programmatically.

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [June 24, 2018, 2:49am UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/7 "2018-06-24T02:49:17Z")

</div>

I tried this in a test program and it worked:

```auto
  size(400, 600,P3D);
  surface.setResizable(true);

```

Check this [https://github.com/processing/processing/issues/3952](https://github.com/processing/processing/issues/3952)

The only trick for me on a Win OS is that the mouse pointer does not change when it hovers on the edge of the window. However, if I click right at the edge and I drag the mouse, the window’s size adjusts to a new size.

Kf

---

<div class="post-metadata">

### Author: ![jay\_m](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jay_m/32/11020_2.png) [@jay\_m](https://discourse.processing.org/u/jay_m)
#### Post date: [November 5, 2020, 9:47pm UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/8 "2020-11-05T21:47:39Z")

</div>

Hi there - I’d like to resurrect this old post as the original question was not really addressed

> [@VansiusProductions](#):
>
> How do i Set Window’s Minimum size when using the P2D renderer?

here is some sample code

```auto
import processing.awt.PSurfaceAWT.SmoothCanvas;
import javax.swing.JFrame;
import java.awt.Dimension;

final static int minWidth=300;
final static int minHeight=300;

void settings() {
  size(500, 500); // will work
  // size(500, 500, P2D); // will fail @build time: ClassCastException: com.jogamp.newt.opengl.GLWindow cannot be cast to processing.awt.PSurfaceAWT$SmoothCanvas
}

void setup() {
  surface.setResizable(true);
  surface.setTitle("Testing Resize");
  surface.setLocation(10, 10);

  SmoothCanvas sc = (SmoothCanvas) getSurface().getNative();
  JFrame jf = (JFrame) sc.getFrame();
  jf.setMinimumSize(new Dimension(minWidth, minHeight));
}

void draw() {
  if ((width <= minWidth) && (height <= minHeight)) background(0xFFFF0000);
  else background(0xFF0000FF);
}

```

when building with `size(500, 500);` all is fine, but if I switch to `size(500, 500, P2D);` it will fail with

ClassCastException: com.jogamp.newt.opengl.GLWindow cannot be cast to processing.awt.PSurfaceAWT$SmoothCanvas

this is pretty self explanatory, clearly the window is no longer of the same type and we have a \* com.jogamp.newt.opengl.GLWindow\* but looking at its documentation I did not find anything related to setting a minimum size.

any hint appreciated if you got this to work.

thanks

Jay.

---

<div class="post-metadata">

### Author: ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)
#### Post date: [November 6, 2020, 10:26am UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/9 "2020-11-06T10:26:27Z")

</div>

Get the window like this:

```auto
import com.jogamp.newt.opengl.GLWindow;

window = (GLWindow) surface.getNative();
window.setResizable(true);

```

Then at the top of `draw()`, include something like this:

`window.setSize(max(window.getWidth(), minWidth), max(window.getHeight(), minHeight));`

… as there doesn’t seem to be a way to set minimum dimensions on the window object:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/3/36b7add136ecf2bdccfe1383263548a749bed876.png)

---

<div class="post-metadata">

### Author: ![jay\_m](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jay_m/32/11020_2.png) [@jay\_m](https://discourse.processing.org/u/jay_m)
#### Post date: [November 6, 2020, 11:29am UTC](https://discourse.processing.org/t/set-windows-minimum-size-when-using-p2d/1192/10 "2020-11-06T11:29:29Z")

</div>

Thanks for the answer and confirming it does not seem to be a way to set minimum dimensions. I was just in denial that in 2020 there would be a package with such a missing feature…

So, yes, feels like that’s last resort solution. it is ugly when resizing compared to the behavior you get without P2D but…

thx again
