We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, all. What I want to do is to display a popup message that blocks the window from closing for the P2D renderer. I could have exit()
make a blocking call, but then the main window doesn't refresh. So what I'd like to do is stop exit()
from being called at all until the popup is dismissed. I can prevent the sketch from closing for the ESC key by intercepting it in keyPressed()
, but I don't know how to make it work when I try to close the window directly via ALT+F4 or the window X button. For the default renderer I could just add an AWT window listener to surface
, but P2D uses GLWindow
as the underlying implementation, and I haven't figured out how to intercept OpenGL window events. So, my question: is what I want possible with P2D, and if so how do I do it?
Answers
I would also love to learn how to do this. Running into serious issues trying to find the x,y coordinates of my Java GLWindow (relative to my screen).
Hey @kchoi,
I think the content in this other thread may help you.
Not sure about the popup window but this prevents an P2D/P3D sketch window from closing using the red cross. It doesn't prevent the ESC key but you already know how to do that. I have not tried using both together - if you do, think about how you are going to eventually close the window ;)
This is a slight modification so it will work with JAVA2D as well as P2D/P3D and is in the same style as I used in the link provided by @crussoma
Tried to add FX2D renderer support but failed! :(
W/o being able to import package javafx in Processing, it doesn't seem to have any hackish way to implement method handle() from interface EventHandler:
http://docs.Oracle.com/javase/8/javafx/api/javafx/event/EventHandler.html
Given that class Stage doesn't have any kinda setDefaultCloseOperation() like the others, we're obliged to use setOnCloseRequest() passing our own EventHandler as its parameter:
http://docs.Oracle.com/javase/8/javafx/api/javafx/stage/Window.html#setOnCloseRequest-javafx.event.EventHandler-
Regardless, gonna post my tweaks for the other PSurface types: :-\"
Oh, I see. What I was failing to do was remove the existing listeners. Perfect, this is exactly what I needed. Thanks, @quark!
Hi. I am also trying to this. I tried using @quark 's code but I'm getting an error on surface.getNative();
The error says: Cannot find anything named "surface"
Make sure you are using Processing 3. If you are then post your code.