tags:

views:

176

answers:

1

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"], ["test, 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

+1  A: 

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

Rob
is there any way to actually add data "column" wise.I can't seem to add more than 1 piece of data to the add_column command :(
Marc Seeger
Looks like rows are first order, columns are second order, which makes sense to me (would get confusing otherwise). What are you trying to do?
Rob