Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JComboBox focus

 
Stefan Jansson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a problem with an editable JComboBox.
When I press my EDIT button, but doesn't do any editing in the JComboBox , and then my OK button I want to get the item in the JComboBox. It is ok when an item in the list is visible but if i have an item which i have put there myself, the call getSelectedItem returns null. I have to klick in the field to get the cursor in it and then its ok.
What i want is some method to get the cursor in there.
I have tried requestFocus but it doesn't work.
please help
/Stefan
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has to be selected for getSelectedItem() to return anything but null. You might look into setSelectedItem() and setSelectedIndex().
 
Stefan Jansson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I called setSelectedItem() with the previus value before I called getSelectedItem() and it works fine. :-D
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic