Replies: 3 comments 13 replies
-
For this example to work, you need to have executed this code once (just once): import py5_tools
py5_tools.processing.download_library('JavaFX') JavaFX needs to be installed this way to trigger py5's support for the JavaFX modules. |
Beta Was this translation helpful? Give feedback.
-
Your initial demo post may be simplified to this: # Uses Imported mode for py5
import javafx.geometry.Pos
def setup():
global colorPicker
size(500, 500, FX2D)
canvas = get_surface().get_native()
pane = canvas.getParent()
colorPicker = javafx.scene.control.ColorPicker()
pane.setAlignment(colorPicker, javafx.geometry.Pos.TOP_LEFT)
pane.getChildren().add(colorPicker)
def draw():
fill("#" + colorPicker.getValue().toString()[2:])
rect(mouse_x, mouse_y, 10, 10) Apparently the root pane for the default Processing window is a StackPane which defaults to a CENTER alignment. This can be changed for each control as shown. The only other thing that's not intuitively obvious is how to convert the color picker value to three separate r,g,b values for use in fill(). |
Beta Was this translation helpful? Give feedback.
-
Looks like someone else had the idea of getting the pane from the PSurfaceFX canvas back in 2016. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently on a bumpy train to PyCon but was able to write a working py5 Sketch that uses JavaFX controls:
I knew this would be possible with the latest py5 release and its support for JavaFX. I'm happy I had some (somewhat) quiet time to work on it.
That JavaFXColorPicker import statement needs to be where it is. If I move it to the top of the file, it will throw an exception and complain JavaFX was not initialized. I'll look into this later to see if I can fix that in a future release.
@vsquared, you know JavaFX controls better than anyone. Please expand this example with what you know to make something magnificent!
Beta Was this translation helpful? Give feedback.
All reactions