Bug in JRuby? Or my problem?

The following short bit of code:

include Java

class TextWindow < javax.swing.JScrollPane
include java.awt.event.KeyListener
def initialize
@text = javax.swing.JTextPane.new
#@text.editable = false
super(@text)
self.addKeyListener(self)
end

ERROR HERE WHEN KEY TYPED

def keyTyped(event)
print “EVENT CHAR #{event.key_char.chr}”
end

def keyPressed(event)
end

def keyReleased(event)
end
end

##################################

def setup_java_window
window = javax.swing.JFrame.new(“Window”)
window.pack
window.visible = true
text = TextWindow.new
window.add(text)
window.setSize(400, 300)
text.grabFocus()
end

setup_java_window

WHEN A KEY IS PRESSED, throws the following odd error:

Exception in thread “AWT-EventQueue-0” file:/usr/local/jruby/lib/
jruby.jar!/builtin/javasupport/utilities/base.rb:26:in `__jcreate!’:
expected [java.awt.Graphics]; got: [java.lang.String]; error: argument
type mismatch (TypeError)
from KeyEventBug.rb:23
…internal jruby stack elided…
from org.jruby.runtime.Block.yield(Block.java:220)
from org.jruby.runtime.Block.call(Block.java:174)
from org.jruby.RubyProc.call(RubyProc.java:173)
from org.jruby.RubyProc.call(RubyProc.java:148)
from org.jruby.javasupport.proxy.JavaProxyConstructor
$1.invoke(JavaProxyConstructor.java:180)
from org.jruby.javasupport.proxy.gen.JScrollPane
$Proxy0.keyTyped(Unknown Source)
from java.awt.Component.processKeyEvent(Component.java:5557)
from javax.swing.JComponent.processKeyEvent(JComponent.java:
2722)
from java.awt.Component.processEvent(Component.java:5379)
from java.awt.Container.processEvent(Container.java:2010)
from java.awt.Component.dispatchEventImpl(Component.java:4068)
from java.awt.Container.dispatchEventImpl(Container.java:2068)
from java.awt.Component.dispatchEvent(Component.java:3903)
from
java
.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:
1826)
from
java
.awt
.DefaultKeyboardFocusManager
.dispatchKeyEvent(DefaultKeyboardFocusManager.java:681)
from
java
.awt
.DefaultKeyboardFocusManager
.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:938)
from
java
.awt
.DefaultKeyboardFocusManager
.typeAheadAssertions(DefaultKeyboardFocusManager.java:810)
from
java
.awt
.DefaultKeyboardFocusManager
.dispatchEvent(DefaultKeyboardFocusManager.java:645)
from java.awt.Component.dispatchEventImpl(Component.java:3941)
from java.awt.Container.dispatchEventImpl(Container.java:2068)
from java.awt.Window.dispatchEventImpl(Window.java:1791)
from java.awt.Component.dispatchEvent(Component.java:3903)
from java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
from
java
.awt
.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:
269)
from
java
.awt
.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:
190)
from
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
from
java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
from
java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

When the same thing is done in NetBeans, it’s reported as KeyTyped
getting a string when it should have gotten a graphics.

Thoughts?

Thanks,
Ken


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

class TextWindow < javax.swing.JScrollPane
include java.awt.event.KeyListener
def initialize
@text = javax.swing.JTextPane.new
#@text.editable = false
super(@text)
self.addKeyListener(self)
end

Kenneth,
Looks like your example is a little off (add_key_listener should be
called on @text, not self).
Because you inherited from a JComponent, Kernel#print will not work
for you (the JComponent subclass stomps it). Here’s the print for
JComponent (which expects a Graphics):

You could use puts, or do Kernel.print instead.

Logan B.
[email protected]
602 714 1148

Could you file a bug for the print anyway? It shouldn’t fail like that.

Kenneth McDonald wrote:

@text = javax.swing.JTextPane.new
JDK 20 Documentation - Home

You could use puts, or do Kernel.print instead.

Logan B.
[email protected] mailto:[email protected]
602 714 1148


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

The print was what was doing it. Adding KeyListener to self is
intentional, for reasons I won’t go into right now :slight_smile:

Thanks,
Ken