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 to see what’s going on inside the P2D renderer to know how to get to the underlying window.
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:
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)
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.
Hi there - I’d like to resurrect this old post as the original question was not really addressed
here is some sample code
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.
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…