Clipboard access in SWT

Hi all,

I wrote a test snippet for clipboard access.

I’m using JRuby 1.6.7 on Windows 7, installed swt 0.12 gem.

I ran the snippet and clicked a get button, it worked well.
But clicked a set button, it didn’t work.

I got the following error message:

C:\tmp>jruby --1.9 clipboard.rb
NameError: no method ‘setContents’ for arguments
(org.jruby.RubyString,org.eclip
se.swt.dnd.TextTransfer) on Java::OrgEclipseSwtDnd::Clipboard
file at test2.rb:36
(root) at test2.rb:42

Umm,… please help me.

ashbb

Just guessing, but shouldn’t the first parameter be an array?
I have been able to get it working using awt before…

https://github.com/rdp/jruby-swing-helpers/blob/master/ruby_clip.rb

Hi Roger,

Thanks for the suggestion.
I’ve revised the code like this: cb.setContents([‘hello hello hello’],
tt)
But umm,… got a similar error message:

NameError: no method ‘setContents’ for arguments
(org.jruby.RubyArray,org.eclips
e.swt.dnd.TextTransfer) on Java::OrgEclipseSwtDnd::Clipboard
file at test4.rb:36
(root) at test4.rb:42

I have been able to get it working using awt before…

https://github.com/rdp/jruby-swing-helpers/blob/master/ruby_clip.rb
Cool!
I’ll study your code and try to merge into my code.

Thanks,
ashbb

I think you might need to use to_java on the RubyArray, to get an array
of
Strings?

Merged and it works now!!

Thank you so much, Roger!!

ashbb