Reputation: 297
I try to use JTable but when I invoke setValueAt method data don't update in gui. I try to find the answer more then 5 hours but anything help me.
I try to updateUI and fireTableDataChanged() but id doesn't help.
I use AbstractTableModel and my constructor is JTable(MemoryTableModel). Look at my code of MemoryTableModel:
What i`m doing wrong, or what I forget?
(Sorry for my english, its not my native language)
public class MemoryTableModel extends AbstractTableModel {
private static final long serialVersionUID = 1L;
ArrayList<ArrayList<Object>> memoryCells;
String[] columnNames = {"Offset", "0", "1", "2", "3", "4", "5", "6", "7", "8",
"9", "A", "B", "C", "D", "E", "F"};
public MemoryTableModel(byte[] data, int cells) {
super();
memoryCells = new ArrayList<ArrayList<Object>>();
for (int i=0; i< cells/16; i++) {
ArrayList<Object> a = new ArrayList<Object>();
a.add(i);
for (int j=0; j<16; j++) {
a.add(data[i*16+j]);
}
memoryCells.add(a);
}
}
@Override
public int getColumnCount() {
return columnNames.length;
}
@Override
public int getRowCount() {
return memoryCells.size();
}
public String getColumnName(int col){
return columnNames[col];
}
@Override
public Object getValueAt(int line, int column) {
return memoryCells.get(line).get(column);
}
@Override
public void setValueAt(Object cell, int row, int column) {
memoryCells.get(row).set(column, cell);
fireTableDataChanged();
}
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (columnIndex == 0)
return false;
return true ;
}
Upvotes: 3
Views: 3673
Reputation: 109815
your notifier fireTableDataChanged();
for setValueAt(Object cell, int row, int column) {
is wrong
you would need to use fireTableCellUpdated, more in linked API
for easier workaround to use DefaultTableModel
, Vector
or util.List
as underlaing array for AbstractTableModel
EDIT
public boolean stopCellEditing() {
and I hope that there is somthing like as JTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
Upvotes: 4