-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling Swing/AWT components with JavaCall on OS X #32
Comments
I've investigated a little bit, and couldn't come up with any answers. It would be good to get this working. |
I ran into this issue too. It occurs even if I just call things like |
Try starting the JVM with "-Djava.awt.headless=true". That will not make graphics work, but might help with the hang. |
That did it, thanks a lot! |
Is there still a problem on OS X? I do not have a problem on Linux. |
FWIW, the Python - Java bridge library jpype also seems to have problems with Swing/AWT on OSX. Something about the threading? I don't understand the reasons fully, as I don't have access to a Mac or do much Java GUI programming. Still, it's reasonable that the issue here has the same underlying cause. Here are two issues with discussions that might be helpful to you: jpype-project/jpype#906 And separately, does this library work on Java 11? If not, are there plans to support it in the future? |
This library does work on Java 11. |
Interesting. The documentation seemed to imply it was only tested on versions 7, 8, and 9. I'm happy this library exists and will start using it. |
Actually, the way I would say it is that the minimum version is now Java 8:
In the JPype issue, did they find a solution? I do not have a Mac to test this code on. My suggestion would be to use interprocess communication rather than in-process interop to get around the GUI issues. For example: Another idea would be to use ZeroMQ (ZMQ) to drive the application. |
No, the JPype issue has not been fixed. They don't have a Mac to test on, and neither do I. Interprocess communication would be slower, and not worth it because doing it in-process is most likely possible. There is information in the discussion for those other two issues that might provide hints for what needs to be done to fix this problem with this library. |
The following runs on my Mac (Sonoma 14.4.1, Intel). The code was run in a Thonny editor with PyObjc plugin. import jpype
import jpype.imports
jpype.startJVM()
import java
import javax
from javax.swing import *
from Cocoa import NSApp
def createAndShowGUI():
frame = JFrame("HelloWorldSwing")
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
label = JLabel("Hello World")
frame.getContentPane().add(label)
frame.pack()
frame.setVisible(True)
javax.swing.SwingUtilities.invokeLater(createAndShowGUI)
NSApp.run() |
Hi there,
i would like to call swing/awt components with JavaCall. But there seems to be some thread issues. Frames do not open.
I think this is not an JavaCall issue but an cocoa/JNI thing but maybe someone knows a workaround for JavaCall on OS X?
Thank you in advance.
Best Max
The text was updated successfully, but these errors were encountered: