Jython Swing超级呼叫将类“扩展"设置为“扩展". JTextField [英] Jython swing supercall to class "extending" JTextField
问题描述
我正在尝试创建类似于此处的面板.但是,如果我尝试为某些方法调用super,它将进入无限递归,从而导致递归限制(对于stackoverflow从来没有更合适的问题;)),这些方法例如是paint
和add
(我尝试过的这两个方法,我想这都是继承的东西.
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()
推荐答案
如果该方法在各自的java类中受保护,则必须使用以下语法(老实讨厌此方法)
If the method is protected in their respective java class, you have to use the following syntax (Honestly hate this method)
self.super__
例如:
from javax.swing import JPanel
class panel(JPanel):
def paintComponent(self, graphic):
self.super__paintComponent(graphic)
# Do something
要调用任何其他超类方法,请使用以下语法:
To call any other super class methods, you use this syntax:
SuperClassName.method(self, *args)
使用新样式类:
super(panel, self).method(*args)
这篇关于Jython Swing超级呼叫将类“扩展"设置为“扩展". JTextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!