atom feed3 messages in org.codehaus.jruby.userRe: [jruby-user] Error when calling p...
FromSent OnAttachments
Kenneth McDonaldAug 19, 2007 6:50 pm 
Bill DortchAug 19, 2007 10:40 pm 
Kenneth McDonaldAug 20, 2007 9:48 pm 
Subject:Re: [jruby-user] Error when calling protected method paintComponent in Java Swing superclass
From:Bill Dortch (bill@gmail.com)
Date:Aug 19, 2007 10:40:49 pm
List:org.codehaus.jruby.user

Protected method support in JRuby is currently very limited -- overriding got snuck in before 1.0, but it isn't quite right, or complete. For now, you'll have to resort to JRuby/Java reflection. Not pretty, but it works:

class Cursor < javax.swing.JLabel # save the superclass method PaintComp = javax.swing.JComponent.java_class.declared_method'paintComponent', ' java.awt.Graphics' #... def paintComponent(graphics) # calling super method PaintComp.invoke(self.java_object, graphics.java_object) end end

We'll should have something better working by 1.1 (while at the same time possibly breaking the hack above).

--Bill

On 8/19/07, Kenneth McDonald <kenn@sbcglobal.net> wrote:

I'm happily using JRuby with Swing, but haven't been able to call a Swing superclass' paintComponent method from JRuby, i.e. in the following:

class Cursor < javax.swing.JLabel def initialize() super("<>") end

def paintComponent(graphics) super(graphics) end end

I get

Exception in thread "AWT-EventQueue-0" nui3.rb:42:in `paintComponent': super: no superclass method `paintComponent' (NoMethodError) from

file:/usr/local/jruby/lib/jruby.jar!/builtin/javasupport/utilities/base.rb:26:in `__jcreate!' from nui3.rb:46 ...internal jruby stack elided...

Using 'paint()' instead of paintComponent() does work, but that's just temporary hack. In the Java class hierarchy, paintComponent is protected while paint is public, and I'm guessing that's the source of the problem. Is there a way around this?

Thanks, Ken

--------------------------------------------------------------------- To unsubscribe from this list please visit:

http://xircles.codehaus.org/manage_email