问题
I am trying to make a custom TextField similar to the panel here. However if I try calling super for certain methods it goes into infinite recursion leading to the recursion limit (never had a more suiting question for stackoverflow ;) ), the methods are for example paint
and add
(those two I tried, I guess it is everything inherited).
Here is the important code excerpt:
class inputWithButtons(JLayeredPane):
def __init__(self):
self.setLayout(_textFieldWithButtons())
self._fileField = JTextField()
self.add(self._fileField, Integer(1))
self.preferredSize = (0, 40) #TODO: why does minimumSize not work?
def add(self, component, layer): #recurses indefinitly
super(inputWithButtons, self).add(component, layer)
self.revalidate()
回答1:
If the method is protected in their respective java class, you have to use the following syntax (Honestly hate this method)
self.super__
ex:
from javax.swing import JPanel
class panel(JPanel):
def paintComponent(self, graphic):
self.super__paintComponent(graphic)
# Do something
Source
To call any other super class methods, you use this syntax:
SuperClassName.method(self, *args)
With new-style classes:
super(panel, self).method(*args)
来源:https://stackoverflow.com/questions/10845209/jython-swing-supercall-to-class-extending-jtextfield