I have been trying to send some data from an Editable JComboBox
to a JXTable
. The code for it goes like this :
private void selectTestActionPerformed(java.awt.event.ActionEvent evt) {
JTextField editorComponent = (JTextField) testName_cb.getEditor().getEditorComponent();
System.out.println(editorComponent.getText());
String data = editorComponent.getText();
Object row = data; /* String to Object casting */
DefaultTableModel model = (DefaultTableModel) testsSelected_table.getModel();
model.addRow(row); /* Error : Cast row to Object or Vector */
}
But the last line of the method model.addRow(row);
says Cast row to Object or Vector
, which it already is.
I may be missing some conceptual or logical part as a beginner. So thought of posting a question here. Can anybody point out my mistake? I would gratefully accept any suggestion(s).
Thanks!!!
It should be an Object[]
. You can do Object[] row = new Object[] { data };
assuming all you want the row to have is one column or data.
Otherwise you can use model.setValueAt(value, row, col)
to set a single value, if that's what you're really trying to do.
For general references, see