-
Does anyone know how to fix this demo? I'm trying to get the JTextArea component to resize with the JFrame and not unable to satisfy the parameter requirement for addComponentListener(something). It seems to want a class for the parameter but I can't come up with the correct syntax. Thanks for any insight. # Uses Import mode for py5
from java.awt import *
from javax.swing import *
from java.awt.event import ComponentListener
_wndW = 400
_wndH = 200
# Unable to extend class with ComponentListener(ComponentListener)
class MyComponentListener:
print("ComponentListener called")
def componentResized(event):
print("component resized")
def componentMoved(event): pass
def componentShown(event): pass
def componentHidden(event): pass
listener = MyComponentListener()
def txtArea():
global frame
txtArea = JTextArea("")
txtArea.setBounds(20,20,_wndW-40,_wndH-40)
frame.add(txtArea)
txtArea.repaint()
def setup():
global frame
size(_wndW, _wndH)
wnd = get_surface()
wnd.set_title('Resizable Window')
canvas = wnd.get_native()
frame = canvas.getFrame()
frame.remove(canvas)
frame.setResizable(True)
txtArea()
frame.addComponentListener(listener) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
You import ComponentListener, but then you overwrite it w/ You may try to inherit from it. Not sure if it works though: |
Beta Was this translation helpful? Give feedback.
-
Asked Bing AI and this is what I've got: from java.awt.event import ComponentListener
from jpype import JProxy
class MyListener:
def componentResized(self, e): print("Resized!")
def componentMoved(self, e): pass
def componentShown(self, e): pass
def componentHidden(self, e): pass
listener = JProxy(ComponentListener, inst=MyListener()) |
Beta Was this translation helpful? Give feedback.
-
@GoToLoop Thank you, thank you! JProxy is your friend. This works: # Uses Import mode for py5
from java.awt import *
from javax.swing import *
from java.awt.event import ComponentListener
from jpype import JProxy
_wndW = 400
_wndH = 200
class MyComponentListener():
global txtArea,frame
def componentResized(event):
txtArea.setBounds(20,20,frame.getWidth()-40,frame.getHeight()-70)
def componentMoved(event): pass
def componentShown(event): pass
def componentHidden(event): pass
listener = JProxy(ComponentListener, inst=MyComponentListener)
def txtArea():
global frame,txtArea
txtArea = JTextArea("")
txtArea.setBounds(20,20,_wndW-40,_wndH-40)
frame.add(txtArea)
txtArea.repaint()
def setup():
global frame,txtArea
size(_wndW, _wndH)
wnd = get_surface()
wnd.set_title('Resizable Window')
canvas = wnd.get_native()
frame = canvas.getFrame()
frame.remove(canvas)
frame.setResizable(True)
txtArea()
frame.addComponentListener(listener) |
Beta Was this translation helpful? Give feedback.
@GoToLoop Thank you, thank you! JProxy is your friend.
This works: