Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with Editable JComboBox ??  RSS feed

 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I am having strange problem getting the entered text in JComboBox. I am using getSelectedItem() for getting the entered text but it gives me the selected Item from the initially populated combo box.

Please tell me how to get the entered text.
Regards,
Vijay
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's what ItemListener is supposed to do... Replace the ItemListener with an ActionListener on your combo box to get the text when the user enters it. If the user enters text and then chooses something else in the ComboBox and then you want to see if they typed anything, you're going to have to add whatever the user typed to the ComboBox in your ActionListener so you can get it from the ComboBox... I don't think the default model saves what you type in the ComboBox by default...

Do something like this...


-Nate

-Nate
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!