Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to active my button when editing JTable?  RSS feed

 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually I add a TableModelListener to myTableModel. After editing a cell, when the focus moves, a TableModelEvent is triggered. I update my button status in the tableChanged()method. But how to trigger an event when focus still at the editing cell? I mean when even the first character entered, my button should be actived.

Thanks.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try setting a custom cell editor:
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.I write a sample as you said, but it doesn't take effect.
 
Brian Cole
Author
Ranch Hand
Posts: 932
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Louis Wang:
I write a sample as you said, but it doesn't take effect.


table.setCellEditor() doesn't do what you think it does. Most people should never call it.

There are a couple of ways to set your custom editor on the table. One of them is table.setDefaultEditor(Object.class, new DefaultCellEditor(field)).
[ October 12, 2007: Message edited by: Brian Cole ]
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Brian Cole:


table.setCellEditor() doesn't do what you think it does. Most people should never call it.

Yes. I set it in another way: table.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(field))

Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!