We are about to switch to a new forum software. Until then we have removed the registration on this forum.
It used to be that a processing 2 applet could be added to a JFrame because it was inherited from Applet which inherits from JPanel. Now it's not.
I see this long discussion: https://forum.processing.org/two/discussion/12774/embedding-papplet-in-java-jframe
but I do not see how to create a JFrame in Java, and add a PApplet as a component. Particularly important is that the PApplet be able resize when told to do so by the layout manager.
Is there any way to do this without using runSketch? It's a real hack to have to have the drawing area create the window.
Answers
Not that I know of. In PS2 the window was always a JFrame no matter which renderer i.e. JAVA2D, P2D or P3D so it was fairly easy to create a JFrame and embed a PApplet in it. With PS3 JFrame is only used with the JAVA2D (default) renderer and uses GLWindow with P2D and P3D.
I realize this cleaned up the codebase, but not being able to embed into a java window with menus and buttons is a major pain. The only thing I was able to suggest to a student is to re-implement the entire Component hierarchy in processing.
@hydrodog===
i was in the discussion you talked about; It was GoToLoop who has given the best way to do what you want; after that i tried by myself and got some results. In the code below you can see that i can create 2 windows with different size, locations, color and so on. But i never found the way to intercept the close button event in order that closing the second window you dont close the first one. If you or anybody can give an hint....As for me, finally, for this work i decided to work in the old P2 way and my app can create 200 windows with 200 instances from Applet...
This hack shows what a terrible decision has been made in the name of performance. I want to try to rip apart the PApplet class and create something that will allow easy integration with other parts of Java.
If you are creating a desktop application with multiple windows then try G4P, it supports multiple windows and you can close the extra windows individually. Also you can specify a function to be executed when the extra window is closed.
Install G4P and try the Mandelbrot example.
Note there are some issues related to windows closing (in P3) this web page has links to info about using G4P windows.