Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Table cells not editable

 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why this isn't working, the table displays fine, I can sort the columns, I can select a cell, but I cannot change the contents inside. I can't see anything that would be turning editing off. Hopefully this is a small enough contained code to work with.


 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please split longer lines of code next time. That way the forum layout is preserved.

Where have you implemented setValueAt? AbstractTableModel.setValueAt does nothing at all, so neither does your table model. You can try to change the values all you want in the GUI, the model ignores these changes and returns the array values you hard coded.
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Please split longer lines of code next time. That way the forum layout is preserved.


Where is too long? 80 chars, 90?


Rob Prime wrote:Where have you implemented setValueAt? AbstractTableModel.setValueAt does nothing at all, so neither does your table model. You can try to change the values all you want in the GUI, the model ignores these changes and returns the array values you hard coded.


I understand that, what I am saying is that I can click on any cell, but I cannot change the contents, even delete. The insertion cursor will not set. I thought that I would still be able to get focus on the cell and modify the contents, but when I moved out of the cell that it would be redrawn. No?
 
Maneesh Godbole
Saloon Keeper
Posts: 11092
13
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether a cell is editable or not is defined by the table model's isCellEditable.
Your model extends the AbstractTableModel whose isCellEditable defaults to false. Override it to return true.
 
Mike Lipay
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Whether a cell is editable or not is defined by the table model's isCellEditable.
Your model extends the AbstractTableModel whose isCellEditable defaults to false. Override it to return true.


Thanks, I hadn't realized it defaulted to false.
 
Rob Spoor
Sheriff
Pie
Posts: 20608
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:Your model extends the AbstractTableModel whose isCellEditable defaults to false. Override it to return true.

Hmmm, I thought it returned true... I probably thought of DefaultTableModel.

Still, without a setValueAt that will actually change the data in the model you can try to edit the contents all you want, as soon as you try to commit (e.g. by pressing enter) you'll see the old data.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic