• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable doesn't display cell data with custom editor applied

 
Jeff Weeks
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey everybody,
I've got a JTable that is editable, and one of the fields is a promo code (which is essentially just a letter from A-Z). Because of the finite number of codes, I've used a JComboBox as a custom cell editor and applied it to that cell:

I can select a promo code just fine from the dropdown, and it will then display as that cell's contents. However, when I load in table data that already has a promo code set, it displays as nothing.
I can confirm that the value is properly set in the table model, it just seems that by adding this custom cell editor, the data in the cell is cleared.
Any ideas why? And is there a way to force this data to be displayed?
Thanks,
Jeff
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added this functionality to a small UI with a table and it seems to function fine. But I want to make sure I understand exactly what your problem is.

I can select a promo code just fine from the dropdown, and it will then display as that cell's contents. However, when I load in table data that already has a promo code set, it displays as nothing.

I was confused initially because the first sentence implies that there is data in the table and it's working fine, and so the second sentence confused me. So I reversed the order of the two sentences in my mind: when you set the table model data everything seems to display correctly except for the promo code field, which is blank (even though the data seems to be there). Then if you select a promo code from the dropdown it will display correctly.
If this is what is happening, then you probably have a problem in the TableModel implementation. That's where the data actually resides, where it is handed off to be displayed (via the "getValueAt()" method) and where it is updated ("setValueAt()" method). Either the data isn't in the model [though you say it is] or it isn't being passed back correctly in the "getValuAt()" method. But it's wierd that it would then start working after you changed a value.
If I haven't read this right, please correct me and explain further the order in which things are happening and where/when the problem occurs.
 
Jeff Weeks
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ahh, right you are!
Definitly was a problem with my model, and a misconception in how I build it from a recursive structure! Argh!
Ironically enough, the only two fields effected by this bug were the two that had drop-down editors... and both of their data was written correctly to the database, so I was totally confused Everything worked... but it didn't... if you know what I mean
Anyway, thanks!
Jeff
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!