You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am having trouble getting a DocumentListener correctly installed on a JTextArea in Swing. The source code is shown below, followed by the error message. It appears that the insertUpdate method is being called but there is an EventQueue error from the EventDispatchThread for some unknown reason. The code was run in a Thonny editor. It initially opens the window without error, but when I try to enter more text there is a spew of error messages and only one character is initially shown in the text area. With further jostling of the text area the remainder of the text will appear. Any insight or assistance would be greatly appreciated. Thanks.
importjpypeimportjpype.importsjpype.startJVM()
importjavaimportjavaximportplatformfromjava.awtimport*fromjavax.swingimport*fromjavax.swing.eventimportDocumentListenerfromjavax.swing.textimportAbstractDocumentfromjavax.swing.textimportPlainDocumentif(platform.system() =="Darwin"):
fromCocoaimportNSApp_wndW=400_wndH=400@jpype.JImplements(DocumentListener)classMyDocumentListener:
@jpype.JOverridedef__init__(self):
print("init called.")
@jpype.JOverridedefchangedUpdate(event):
print("changed update")
@jpype.JOverridedefremoveUpdate(event):
print("remove update")
@jpype.JOverridedefinsertUpdate(event):
print("insert update")
defbuildWnd():
globaltxtAreaglobalmyListenerglobalframeframe=JFrame("Add More Lines of Text")
frame.setLayout(None)
frame.setBounds(100,100,400,400)
txtArea=JTextArea("Jeremiah was a bullfrog.")
txtArea.setBounds(10, 10, _wndW-20, 300)
frame.add(txtArea)
txtArea.repaint()
print("Document =",txtArea.getDocument())
myListener=MyDocumentListener()
print("myListener =",myListener)
# This causes an error message and doesn't work correctlytxtArea.getDocument().addDocumentListener(myListener)
frame.setVisible(True)
# EDT causes EventQueue errorjavax.swing.SwingUtilities.invokeLater(buildWnd)
print(platform.system())
if(platform.system() =="Darwin"):
NSApp.run()
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am having trouble getting a DocumentListener correctly installed on a JTextArea in Swing. The source code is shown below, followed by the error message. It appears that the insertUpdate method is being called but there is an EventQueue error from the EventDispatchThread for some unknown reason. The code was run in a Thonny editor. It initially opens the window without error, but when I try to enter more text there is a spew of error messages and only one character is initially shown in the text area. With further jostling of the text area the remainder of the text will appear. Any insight or assistance would be greatly appreciated. Thanks.
Error message:
This error message appears to be repeated in the console with every keystroke.
Beta Was this translation helpful? Give feedback.
All reactions