This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Table cells not editable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Table cells not editable" Watch "Table cells not editable" New topic
Author

Table cells not editable

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
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

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
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

Joined: Jul 26, 2007
Posts: 10167
    
    8

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
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

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Table cells not editable
 
Similar Threads
DecimalFormat error
Is there a way to show an image in a JTable as a thumbnail?
Out of bound on removeRow
JTable dates
JTable cell alignment