Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting Cell Editors in J(X)Table  RSS feed

 
Alaneus Kingingestingest
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have table (JXTable) which has columns of type: String, Date and some custom objects.
So I created TableModel for table and set table cell editors by calling:

myTable.setDefaultEditor(MyCustomClass.class, new DefaultCellEditor(new JComboBox(new MyCustomClassComboBoxModel())));
myTable.setDefaultEditor(Date.class, new JDateChooserCellEditor());

I recently noticed that if I want to edit some String column I can normally double click on it and it would go to editing mode, but I can not go to editing mode if I first double click on columns of type: Date or MyCustomClass.
So when I open frame that contains table if I want to edit some Date or MyCustomClass columns I have to click on some String column first to go to editing mode, and then everything works OK (I can edit Date and MyCustomClass columns).
But if I first double click on Date or MyCustomClass columns nothing happens (it does not go to editing mode).

Can somebody explain what am I doing wrong?

Thanks
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us some code from the two editors you've created? Especially the shoudSelectCell, isCellEditable and getTableCellEditorComponent methods.
 
Alaneus Kingingestingest
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDateChooserCellEditor I didn't create. I'm simply using com.toedter.calendar.JDateChooserCellEditor.
And for my custom class cell editor I used DefaultCellEditor and put my ComboBoxModel for that custom class, as I mentioned:
 
Alaneus Kingingestingest
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also noticed that Boolean type cells which cell editors I didn't even set (JXTable sets it by default), also have this problem of not getting to editing mode unless some String type cell first is double clicked?!?

In my TableModel among other methods I overrided:
 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you show us the implementation for those methods?

JTable uses isCellEditable to determine whether or not a cell can be edited. It uses getColumnClass to help determine the renderer / editor for a column. Boolean and the numeric types have built-in renderers / editors, that's why you saw a check box for the boolean class.
 
Alaneus Kingingestingest
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just put my TableModel in JTable, and everything worked ok.

After much of research I found solution for JXTable:
table.setTerminateEditOnFocusLost(false);

References:
http://forums.java.net/jive/thread.jspa?threadID=64281&tstart=1

 
Rob Spoor
Sheriff
Posts: 21092
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for sharing the solution
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!