Swing Components in Default Processing Window_py5

Do you mean no callback for SwingUtilities.invokeLater()?
Well, you haven’t added 1 for your original py5 sketch either!
And all of my sketches here are based on your 1st py5 sketch!

Although it’s indeed highly recommended to use invokeLater() to do anything related to Swing components, sketches that directly create and add simple components within setup() had no issues since Processing 1!

A Processing sketch by default has only 2 active threads:
The “Animation Thread” & the “AWT-EventQueue-0” (EDT) for the JAVA2D renderer.

Code running within setup() and on is already under the “Animation Thread” btW.

The reason why code running under the “Animation Thread” can manipulate AWT/Swing GUI w/o any repercussions is b/c there’s no other thread doing the same at the same time.

The “Animation Thread” only deals w/ the Swing JFrame when it updates its canvas after draw() is done.

So any code running under the “Animation Thread” is guaranteed not to mutate the GUI while Processing is busy repainting/updating its canvas.

1 Like