Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Editable JComboBox as cell editor in JTable

 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
as the subject says I'm using a JComboBox as cell editor in JTable
if the combobox is not editable all works perfect
if I set the combo box to be editable, allowing the user to enter free form text, the user can add the text but when he moves to another cell it disapears, what else do I need to do to get it to work??
I set it up like this
JComboBox combo = new JComboBox ();
combo.addItem("foo");
combo.addItem("bar");
combo.setEditable(true);
TableColumn col = getColumn(6);
col.setCellEditor(new DefaultCellEditor(combo));
do I need to do something else??
Thanx
Dave
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you are doing should work. I went to the How to Use Tables tutorial on SUN, downloaded the example that uses a combobox for an editor (TableRenderDemo.java) and added "comboBox.setEditable(true);" to the source. It compiled and worked just fine, meaning I could select a value from the dropdown list, or enter a new value, and the table was updated accordingly.
Is it possible that there's something funny in the "setValueAt(...)" method (of your Model class) that checks the new value and throws it away if it doesn't match what is in the list? That would explain the behavior.
 
Dave Robbins
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OUCH!!
as you noted, my example works perfectly with a JTable
I should have explained in more detail
I'm actually using a third party table that is derived from a JTable
apparently the third party class is the problem
I went back and tried it with plain old JTable and it works fine
shoulda done that in the first place
thanx for helping me figure it out
time for third party tech support :roll:
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic