Jython swing supercall to class “extending” JTextField

久未见 提交于 2019-12-12 18:31:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!