Replies: 3 comments 2 replies
-
If we don't use the SwingUtilities thread and do something like the following it appears that the imports are being used, but still there is no frame displayed. Are we missing a renderer or event loop? I tried using asyncio but that made no difference. import jpype
import jpype.imports
jpype.startJVM()
import java
import javax
from javax.swing import *
def buildWnd():
print("======= buildWnd begin =========")
frame = JFrame("Hello Swing")
frame.setBounds(100, 100, 400, 400)
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setVisible(True)
print("frame =",frame)
print("======= buildWnd end ===========")
if __name__ == '__main__':
buildWnd() |
Beta Was this translation helpful? Give feedback.
-
All GUIs require a service thread. That is something that takes events and routes them to a common place to be handled. Your issue here is not JPype, but rather how to use swing. You either need to tell the main thread to be adding as the servicing thread, or create a new Java thread and have it run the GUI servicing loop. My recommendation would be test what you are trying to do in Java first because until you have properly set up the GUI servicing in Java, how to make it work through Python is going to be a challenge. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
I am unable to run this demo which came from 'JPype User Guide' on a mac (Sonoma 14.4.1, Intel chip). Is there a known fix?
Addendum:
I'm running this code in a Thonny editor with the following JPype installed:
The error analysis by Thonny indicates that JFrame and JLabel are not defined. Thanks for any help or insight.
Beta Was this translation helpful? Give feedback.
All reactions