I was trying to put table in JPanel, here's a piece of code:
innerPane = JPanel.new(BorderLayout.new)
tab = javax.swing.table.DefaultTableModel.new
tab.add_column("id")
tab.add_column("something")
tab.add_row(["1","bla"].to_java)
tab.add_row(["2","bla bla"].to_java)
innerPane.add(tab, BorderLayout::CENTER)
And in the last line (innerPane.add
) I'm getting this error:
no method "add" for arguments (javax.swing.table.DefaultTableModel)
How can I add table to panel then, if not like this?
The DefaultTableModel
has no visual display component and needs to belong to a JTable
.
The JTable itself is used to display the data provided by the model. The JTable view can be changed without affecting the model. Any changes to the model affect the JTable.
I don't know the Jruby portion, but in Java:
JTable table = new JTable(tab); //instantiate a JTable widget to a model tab
Then, you can add the JTable Swing Component using your provided code
innerPane.add(table, BorderLayout::CENTER)