Reputation: 3
Assign Object[] to Object[]
public TableDB(){
model = new DefaultTableModel();
table = new JTable(model){/*{ public boolean isCellEditable(int rowIndex, int colIndex) {
return editMode; //Disallow the editing of any cell
}}*/;
/*public Class<?> getColumnClass(int columnIndex) {
switch (columnIndex) {
case 0:
return String.class;
case 1:
return Integer.class;
default:
return Boolean.class;
}}*/};
addColumnFromDB();
addDataFromDB();
JScrollPane scrollPane = new JScrollPane(table);
//model.addColumn("Name");
//model.addColumn("Score");
//
this.add(new JScrollPane(table));
table.setCellSelectionEnabled(false);
}
public void addDataFromDB(){
Object[] data = bl.getData();
for(int i = 0;i<data.length;i++){
model.addRow(data[i]);
}
}
Other class
public Object[] getData()
{
Object[] data ={"a"};
return data;
}
Compiler says "no suitable method found for addRow(java.lang.Object)" but i use Object[]
The problem is in model.addRow(data[i]);
Upvotes: 0
Views: 71
Reputation: 2185
Here is specification of addRow
addRow
public void addRow(Vector rowData)
Adds a row to the end of the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.
Parameters:
rowData
- optional data of the row being added
addRow
public void addRow(Object[] rowData)
Adds a row to the end of the model. The new row will contain null values unless rowData is specified. Notification of the row being added will be generated.
Parameters
:
rowData
- optional data of the row being added
and you are passing
model.addRow(data[i]);
but it requires Object[]
Upvotes: 0
Reputation: 21902
I think you should be doing the below code, if you are, as I assume, using DefaultTableModel
public void addDataFromDB(){
Object[] data = bl.getData();
model.addRow(data);
}
Upvotes: 1
Reputation: 9946
Signature of addRow method is addRow(Object[])
so you need to pass an array of Objects rather than individual Object. Try
model.addRow(data);
Upvotes: 0
Reputation: 69440
The method addRow needs an Object[]. You give him a Object.
Try model.addRow(data);
Upvotes: 0
Reputation: 3748
If you are using http://docs.oracle.com/javase/7/docs/api/javax/swing/table/DefaultTableModel.html#addRow%28java.lang.Object[]%29 then you need to provide the whole array, not just an element of it. So it should be like this: model.addRow(data);
Upvotes: 0