• 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

Editable JComboBox as cell editor in JTable

 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic