Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Focus problem in 1.4_2 when JPopupMenu show is called

 
David Chen
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, there:

I have an application, with a JTextField when that textfield gained focus, a popup menu is shown, and when it lost focus, the popup menu is hidden.
My focus listener class is listed below, where popup is JPopupMenu, and function displayPopup() is just to call show() in JPopupMenu:

Everything works fine in jdk 1.3 version. In jdk1.4_2 version, I met following issues:
1. whenever the text field gained the focus, the application keeps calling "focusGained()", and "focusLost()" functions endlessly (it seems the system keeps sending those focus events endlessly);
2. if I removed that "popup.setVisible(false)" in focusLost, then, it seems no other component can gain the focus anylonger.

So, very appreciated if anyone can give me some help, is that a bug in 1.4.2 or is there any way to work around?

Thanks a lot

David
 
David Chen
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just wonder, does that mean when JPopupMenu.show is called, the "lost focus" event is sent to invoker, and when JPopupMenu is hidden, the "gain focus" event is sent to its invoker again?

Appreciated if any suggestion on this issue

Thanks a lot in advance
David
 
Tom Nielsen
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
displayPopup gives focus to popup and your textfield looses focus and calls
popup.setVisible(false) which gives focus back to your textfield which then calls displayPopup and ... you get the picture?
When you remove popup.setVisible(false), your popup will have focus and have its own focuscycle
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic