JTable se value
I'm trying to set the values at in my JTable but the values aren't appearing.
Heres my code, can anyone tell me what I'm doing wrong?
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
publicclass CreateJTableextends JDialog{
public CreateJTable(){
TableModel dataModel =new AbstractTableModel(){
publicint getColumnCount(){
return 4;
}
publicint getRowCount(){
return 10;
}
public Object getValueAt(int row,int col){
return" ";
}
};
JTable table =new JTable(dataModel);
table.setValueAt("#", 0, 0);
table.setValueAt("Aplaha", 2, 2);
// Retrieve the value in the visible cell (1,2)
int rowIndex = 1;
int vColIndex = 2;
Object o = table.getValueAt(rowIndex, vColIndex);
// Retrieve the value in cell (1,2) from the model
rowIndex = 1;
int mColIndex = 2;
o = table.getModel().getValueAt(rowIndex, mColIndex);
// Change a cell in the 2nd visible column
rowIndex = 2;
vColIndex = 1;
table.setValueAt("New Value", rowIndex, vColIndex);
// Change a cell in the 3rd column in the model
rowIndex = 3;
mColIndex = 2;
table.getModel().setValueAt("New Value", rowIndex, mColIndex);
JScrollPane scrollpane =new JScrollPane(table);
setSize(400, 400);
getContentPane().add(scrollpane);
setVisible(true);
}//end constructor
}

