File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Editable JComboBox as cell editor in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Editable JComboBox as cell editor in JTable" Watch "Editable JComboBox as cell editor in JTable" New topic
Author

Editable JComboBox as cell editor in JTable

Dave Robbins
Ranch Hand

Joined: Sep 16, 2003
Posts: 131
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

Joined: Sep 03, 2003
Posts: 399
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

Joined: Sep 16, 2003
Posts: 131
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
 
Don't get me started about those stupid light bulbs.
 
subject: Editable JComboBox as cell editor in JTable