Replies: 7 comments 4 replies
-
Beta Was this translation helpful? Give feedback.
-
No longer a problem of running the code. I finally got the latest version of py5 and py5_tools installed on my Windows 11 system (had to do everything manually). I was able to install javafx with py5_tools and now I can get a window with this code. However, now there is a new issue which is this error message:
I now have a FX2D window but am not able to add anything to it. |
Beta Was this translation helpful? Give feedback.
-
I think the problem lies in py5.core.Sketch.setup as indicated in the error message: import java.awt.Canvas;
...
public void setup() {
if (success) {
PSurface surface = getSurface();
// request focus for Java2D and FX2D renderers on Windows and MacOS
if (platform == WINDOWS && (sketchRenderer().equals(JAVA2D) || sketchRenderer().equals(FX2D))) {
Canvas canvas = (Canvas) surface.getNative();
canvas.setFocusable(true);
canvas.requestFocus();
} else if (platform == MACOS && (sketchRenderer().equals(JAVA2D) || sketchRenderer().equals(FX2D) || g.isGL())) {
ThinkDifferent.activateSketchWindow();
} Proposed change: |
Beta Was this translation helpful? Give feedback.
-
As it turns out getting py5 to recognize 'import javafx' was not possible in my attempts. Upon looking at the code again its primary function was to setFocus on the canvas which is not really necessary in my opinion, so I deleted it and re-compiled the py5.jar according to instructions on the website and it worked. My code changes are shown below:
Sketch code: import javafx
_wndW = 400
_wndH = 300
def myBtnAction(evt):
print("You hit the button.",evt)
def setup():
size(_wndW, _wndH,FX2D)
window_title("JavaFX Default Window")
canvas = get_surface().get_native()
root = canvas.getParent()
pane = javafx.scene.layout.Pane()
btn = javafx.scene.control.Button("Push Me")
btn.setLayoutX(30)
btn.setLayoutY(30)
btn.setOnAction(myBtnAction)
pane.getChildren().add(btn)
root.getChildren().add(pane)
def draw():
fill(0,0,255)
circle(200,100,100) A DropBox link to my recompiled py5.jar is here if anyone else wants to try it: |
Beta Was this translation helpful? Give feedback.
-
The correct code change here is to modify the conditional so that it does
not include FX2D on Windows. That code is needed for JAVA2D.
For your modification, does the window get focus? Does it ever open behind
other windows?
…On Fri, Jun 20, 2025, 5:55 PM vsquared ***@***.***> wrote:
As it turns out getting py5 to recognize 'import javafx' was not possible
in my attempts. Upon looking at the code again its primary function was to
setFocus on the canvas which is not really necessary in my opinion, so I
deleted it and re-compiled py5.jar according instructions on the website
and it worked. My code changes are shown below:
//import java.awt.Canvas;
...
public void setup() {
if (success) {
PSurface surface = getSurface();
// request focus for Java2D and FX2D renderers on Windows and MacOS
if (platform == WINDOWS && (sketchRenderer().equals(JAVA2D) || sketchRenderer().equals(FX2D))) {
// Canvas canvas = (Canvas) surface.getNative();
// canvas.setFocusable(true);
// canvas.requestFocus();
} else if (platform == MACOS && (sketchRenderer().equals(JAVA2D) || sketchRenderer().equals(FX2D) || g.isGL())) {
ThinkDifferent.activateSketchWindow();
}
Sketch code:
import javafx
_wndW = 400_wndH = 300
def myBtnAction(evt):
print("You hit the button.",evt)
def setup():
size(_wndW, _wndH,FX2D)
window_title("JavaFX Default Window")
canvas = get_surface().get_native()
root = canvas.getParent()
pane = javafx.scene.layout.Pane()
btn = javafx.scene.control.Button("Push Me")
btn.setLayoutX(30)
btn.setLayoutY(30)
btn.setOnAction(myBtnAction)
pane.getChildren().add(btn)
root.getChildren().add(pane)
def draw():
fill(0,0,255)
circle(200,100,100)
Output on Windows 11:
w11.png (view on web)
<https://github.com/user-attachments/assets/81603dfe-723d-4898-beb0-4e522c895ba9>
—
Reply to this email directly, view it on GitHub
<#665 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA63L67QGUPX6R5XEHWELU33ER7MDAVCNFSM6AAAAAB7QUV7XWVHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTGNJTGQ2DQNY>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
# Uses Imported mode for py5
def setup():
size(400,400,JAVA2D)
get_surface().set_always_on_top(True)
background(209);
def draw():
fill(0,255,0)
circle(100,100,100) In my opinion asking a window component (canvas in this case) to be in focus and then expecting the window itself to be in front is not likely to work (if I'm understanding correctly). Nonetheless, you must have had some positive experience doing things this way or you wouldn't have put it in. My experience in objc is a little different. |
Beta Was this translation helpful? Give feedback.
-
I'm just curious, isn't JAVA2D the default renderer? If it is, then why is it even an option? |
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 don't understand why this won't run in Windows11:
Error:
Beta Was this translation helpful? Give feedback.
All reactions