简体   繁体   中英

DefaultTableModel not accepting Object type


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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM