Bug in editable JComboBox?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Bug in editable JComboBox?

 
0
  #1
Aug 12th, 2008
Hi,

I have a swing app where I am using (among other things obviously) an editable JComboBox and a jButton.

when the JButton is clicked, it does some processing and uses the value in the JComboBox as one of it's inputs. I'm finding that everything is fine when:

- The value of the combobox is changed via the drop down
- The value of the combox is changed by typing AND the user either tabs or clicks on another field

however, if the user changes the value of the combobox by typing and then clicks on the button, the OLD value of what was in the combox is what the JButton sees when doing the getSelectedItem(). If the user clicks on the button a second time, then the new value is available via the getSelectedItem().

is this a known issue or are there any workarounds available? i was thinking that when the user clicks the button I would just 'pretend/force a focus change' as if the user had clicked on another field prior to hitting the button.

Any recommendations would be welcome.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Bug in editable JComboBox?

 
0
  #2
Aug 15th, 2008
Apparently this is a known bug in java - see link below:
http://bugs.sun.com/bugdatabase/view...bug_id=6729824

I got around it by doing mycombox.getEditor().getItem() rather than mycombox.getSelectedItem().
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC