3

I am constructing a JTable for an Applet that should be able to handle user edits. As such, I have extended the AbstractTableModel and have successfully populated the table with data. My problem is that once the data has been populated, clicking on the table does not allow for edits.

I have overridden the isCellEditable() method to always return true, as well as print a message to the console every time the method is invoked. However, when I interact with the table (through any number of consecutive mouse clicks on any given single cell), the cell does not become editable, and isCellEditable() never gets called either.

My question is, what needs to be called in order to edit a particular cell? I apologize for the lack of code in the post, but the code is highly proprietary, and my superiors are very strict on releasing any code.

wattostudios
  • 8,666
  • 13
  • 43
  • 57
user1431513
  • 33
  • 1
  • 3

2 Answers2

4

To protect your superiors' interests, edit your question to include an sscce that exhibits the problem you describe. Several example suitable for a starting point may be found in How to Use Tables, and this example illustrates an editable AbstractTableModel. You might compare it with your implementation.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
3

1.are you added AbstractTableModel to the JTable already visible on the screen

2.if yes then codes lines isn't isCellEditable(), but should be

@Override
public boolean isCellEditable(int row, int column) {
    return true;
}

3.I'd suggest to use DefaultTableModel rather than to override required methods for AbstractTableModel

mKorbel
  • 109,525
  • 20
  • 134
  • 319
  • I really don't understand why you recommend DefaultTableModel over an AbstractTableModel. It requires copying and thus duplicating information between your domain objects and (gasp) Vectors, and doing the same thing in the other direction when it's editable. Why not just use the domain objects directly. Much less messy, IMHO. – JB Nizet Jun 02 '12 at 07:38
  • @JB Nizet `DefaultTableModel` required nothing, any knowledge about `something`, about `Java`, `JTable`, its `Model`, in the `DefaultTableModel` is possible to override the same way to all accesible methods, agreed that with limitations to using `Vector` or `double Array`, my view is but why bothering with methods that, why complicating simple things, especially if they are works from default setting came from API, – mKorbel Jun 02 '12 at 10:08
  • Option #2 worked for me, thank you very much. Would you mind explaining why it's different once the table has been added to the screen? – user1431513 Jun 04 '12 at 17:06