As I suspected, the invoke below calls the sub-class method recursively. Any ideas on how I call the parent?
I also tried getMethods and printed out all of the methods. Curiously it listed the sub-class requestFocusInWIndow twice. -----Original Message----- From: Dan Patten [mailto:[EMAIL PROTECTED]] Sent: Friday, August 30, 2002 11:25 AM To: JDJList Subject: [jdjlist] How to invoke method of super class using reflection We are flipping back and forth between 1.3.1 and 1.4.1 right now. We wanted to handle a change from requestFocus used in 1.3.1 and prior to requestFocusInWindow. We have a number of our own classes that extend Swing Components so we thought we could over-ride requestFocusInWIndow so that it would work whether we compiled in 1.3.1 or 1.4.1. We though we might do the following: public boolean requestFocusInWindow(){ if (IS_JRE_1_3){ requestFocus(); return false; } try{ java.lang.reflect.Method requestFocusInWindow = super.getClass().getMethod("requestFocusInWindow",null); Object result = requestFocusInWindow.invoke((JButton)this,null); // .invoke(super,null); doesn't compile return ((Boolean)result).booleanValue(); } catch(Exception e){ return false; } } My question is will the invoke statement actually invoke the JButton.requestFocusInWindow or will it recurse into this sub-class method? To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm
