Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Hiding a JComboBox's popup window

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have an application with numerous JTextFields and JComboBoxes, and need to perform validation on the JTextFields to confirm that the entry is a valid number, within the defined range, etc. I use a KeyListener and FocusListener for this, and it works fine as long as I just navigate using the tab key.
Things get strange however, when there is an invalid entry in one of the JTextFields, and the user selects one of the JComboBoxes with the mouse. The JOptionPane with the error message pops up and the focus is returned to the original JTextField when the user hits the "okay" button, as it should be. The problem is that the popup window from the JComboBox I tried to select is still shown. This is despite the fact that the caret is back in the original JTextField. I have to click somewhere on the panel to get the popup window to close.
I would have thought that the focusGained event would fire on the JComboBox (how else would it know to display the popup?), but this doesn't happen. I've tried println statements everywhere in the possible JComboBox's events, but nothing seems to fire. Once I can determine which event fires, then it should be simple to use the hidePopup() method to close the popup. What am I missing here?
The code below is taken from the focusLost event in the FocusListener I use with the JTextFields. I'm wondering if the way I'm displaying this error message may be the problem.

Any suggestions would be greatly appreciated.
[This message has been edited by Al Heinrichs (edited June 17, 2001).]
Yeast devil! Back to the oven that baked you! And take this tiny ad too:
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!