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

Getting Lost Focus from JComboBox  RSS feed

 
Udaya Bascar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a interface
which has a textfield and combobox and
a JTable
on lost focus of combobox i want to
populate my JTable
my code
jcmbBox.addFocusListener(new FocusAdapter()
{
public void focusLost(FocusEvent e)
{
JoptionPane.showMessageDialog(null,"Lost Focus");
}
});
i am testing it by using a MessageBox as above
MessageBox is not firing
can anyone come with a handy solution
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, behind a JComboBox, there are two components,
a renderer and an editor. So you have to add your Listener to the editor of the JComboBox. You can get it with:
yourComboBox.getEditor().getEditorComponent();
Then you can add your listener to this component and not to your ComboBox.
Hope this works
Rene
 
Udaya Bascar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
myComboBoxName.getEditor().getEditorComponent().addFocusListener(new FocusAdapter()...

is it ok
 
Rene Liebmann
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it looks good. And does it work?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!