Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Setting Cell Editors in J(X)Table

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 22458
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 22458
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 22458
121
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for sharing the solution
 
a wee bit from the empire
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic