vendredi 29 janvier 2016

Invoke Superclass method via reflection

I'm using an Eclipse based software which allows to create applications and automatically provides a default user interface. I'm trying to modify this interface (e.g. change buttons icon, foreground color etc...) but unfortunately I cannot modify the source code, so I'm trying to do it via java reflections. I can anyway take vision of the compiled jar files thanks to softwares like JD-GUI, but I'd prefer not to modify and recompile the jars. The problem is that this interface is built through customized classes which extends Swing components and, looking into the jar files, I found some annoying tricks implemented. Follows an example:

final class MyToggleButton extends JToggleButton{
    MyToggleButton (ImageIcon defaultIcon){
        super.setIcon(defaultIcon);
    }
    @Override
    public void setIcon(Icon icon){}
}

With classes built in this way, if I invoke the setIcon() method on an instance of MyToggleButton, it doesn't make effect, since the override method has no code inside (I think). So I cannot change the icon they set by default on the specific button.

Does anyone know a way to overcome this issue? Thanks in advance for any help.

P.S. I'm not a javer but I'm quite familiar with reflections.





Aucun commentaire:

Enregistrer un commentaire