aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Editable JComboBox in JTable not working without hitting Enter Key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Editable JComboBox in JTable not working without hitting Enter Key" Watch "Editable JComboBox in JTable not working without hitting Enter Key" New topic
Author

Editable JComboBox in JTable not working without hitting Enter Key

Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Hi,

i have a problem using an editable JComboBox as cell editor in a JTable.

When i edit the combo and then I press the TAB or ENTER key then all works fine and the value in the TableModel is updated with the edited one,
but
if i leave the cell with the mouse
or
traverse to another cell through arrow keys
or
click on any other cell, the typed value is going off

and the value is not passed to the TableModel. Why ? Is there a way to solve this problem ?

Regards
Priya Sri
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Next time I suggest you SearchFirst because I have posted this code at least 2 or 3 times before, in answer to similar questions.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
I have added this line. But it is not working.
Can you describe in detail.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

Ehm sorry. "val" should be Boolean.TRUE.
Priya Sri
Ranch Hand

Joined: Mar 30, 2004
Posts: 84
Rob,

Tried this. but no change...

If you have an examples of editable Jcombobox in JTable working without hitting enter key... I searched in this site as well.. but not found useful links. please post that if you have any.

Example : Jcombobox has 3 choices. On selecting 3 rd choice, it should become editable and user should key the value. Now at this point, user move the tab or click on the mouse, the entered value should be selected in the jcombo box.

But jcombobox is taking the value only on click of enter key.

Thanks.
Alfred Brookman
Greenhorn

Joined: Oct 08, 2010
Posts: 1
i have _exactly_ the same problem. i already wasted hours to find a solution, but no luck.
i would be glad for any help!

while implementing my own CellEditor i found out, that getCellEditorValue() is called before the editable combox has "updated" the string. so getSelectedItem() still returns the old value but shortly after that it would return the right value!
somehow there should be a method like "combobox.stopEditing()" or something...


my example:


EDIT: I found a solution! This does the trick:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Editable JComboBox in JTable not working without hitting Enter Key