Swing Components in Default Processing Window #457
Replies: 7 comments 15 replies
-
Link above is apparently dead; will try again: https://discourse.processing.org/t/swing-components-in-default-processingwindow/35483 |
Beta Was this translation helpful? Give feedback.
-
getFrame() runs without error: Now I should be able to start building Swing components in the default window. Thanks a million. There may be more questions later. |
Beta Was this translation helpful? Give feedback.
-
The following demo will give you some idea of what is possible. Swing components were placed in the default Processing window using the same technique that was used in Processing 4. Once the frame is obtained it is important to remove the canvas in order for the controls to show up. On a Mac it is necessary to retain draw() even though it is non-functional; otherwise there is a flash and the window disappears at app launch. I was unable to use a separate thread for the swing components (as required in Processing), but in py5 that doesn't appear to be a problem (as far as I am aware at this point). For some reason I couldn't get the ComboBox to work correctly (it only shows up when clicked on and there are no up/down arrows displayed), but I left the REMmed out code in anyway. The next hurdle is to get event handling to work. The controls are there, but they don't do much at this point. At any rate, the demo should serve as proof of concept.
|
Beta Was this translation helpful? Give feedback.
-
The following demo shows how to change the size of the canvas to allow room for controls at the top, thereby retaining the functionality of draw(). Buttons are placeholders only and will need to be hooked up later when it is known how to install event handlers.
|
Beta Was this translation helpful? Give feedback.
-
With |
Beta Was this translation helpful? Give feedback.
-
As it turns out it's pretty simple to add a slider to change the circle diameter. Just make a global of the slider and use its value to draw the circle. Also added r,g,b sliders to change color of circle (would normally use JColorChooser hooked to a button).
Improved version:
|
Beta Was this translation helpful? Give feedback.
-
The following source code is an example of a JButton event handler:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am new to Py5 but have used Processing for a few years and have a special interest in controls for the user interface. I have previously used Swing components in the default Processing window by adding them to the frame and deleting the default canvas. An example of what I have done in the past is here: https://discourse.processing.org/t/swing-components-in-default-processingwindow/35483. I would like to do something similar in Py5, but am unable to get the frame to accomplish this. My operating system is MacOS with Sonoma 14.1.1. Below is the Py5 code that I use in a Thonny editor to get the window object and canvas. I have been told that I might have a defective py5 installation, but have no idea how it is supposed to work. I have successfully placed Swing components on both a JFrame and an AWT Frame, but currently am unable to do any event handling. I would prefer to use the frame of the default window if possible. Thanks in advance for any help.
Previous Work Done in Processing 4:

Beta Was this translation helpful? Give feedback.
All reactions