开发者

JRuby and Swing DefaultTableModel ("no constructor with arguments matching[...]")

I use Swing from JRuby and I am trying to set up a JTable with a TableModel as input.

table_headers looks something like this: ["bla", "narf", "poit"]

table_data looks something like this: [["one", "two"], ["t开发者_如何学JAVAest, test"], ["hello", "world"]]

my_model = javax.swing.table.DefaultTableModel.new(table_data,table_headers) results in

C:/jruby/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb:51:in `new': no constructor with arguments matching [class org.jruby.RubyArray, class org.jruby.RubyArray] on object (NameError)

my_model = javax.swing.table.DefaultTableModel.new(table_data.to_java,table_headers.to_java) results in

C:/jruby/lib/ruby/site_ruby/shared/builtin/javasupport/java.rb:51:no constructor with arguments matching [class org.jruby.java.proxies.ArrayJavaProxy, class org.jruby.java.proxies.ArrayJavaProxy] on object (NameError)

Any idea how to solve this?

Also: Isn't there an "easy" way to simple create a table and set the fields?

(e.g. something along the lines of:

bla = SomeTable.new(5,5)

bla[2][1] = "edited"

)

p.s. as you might see from the errormessage, I have to use windows


I've seen this kind of thing before with classes that have multiple constructors with similar number of args (but differing type). JRuby sometimes has trouble picking which constructor you mean to hit (the same goes for overloaded methods). It's easy to see why in this case: some constructors take Object[].

Luckily you can add your columns and data after instantiation:

m = javax.swing.table.DefaultTableModel.new
m.add_column("id")
m.add_column("name")
m.add_row(["1", "jimmy"].to_java)
m.add_row(["2", "robert"].to_java)

...etc

Also: Isn't there an "easy" way to simple create a table and set the fields?

You could create your own wrapper, or take a look at MonkeyBars or profligacy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜