aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Focus problem in 1.4_2 when JPopupMenu show is called Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus problem in 1.4_2 when JPopupMenu show is called" Watch "Focus problem in 1.4_2 when JPopupMenu show is called" New topic
Author

Focus problem in 1.4_2 when JPopupMenu show is called

David Chen
Ranch Hand

Joined: Jan 06, 2002
Posts: 57
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

Joined: Jan 06, 2002
Posts: 57
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

Joined: Feb 17, 2005
Posts: 1
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Focus problem in 1.4_2 when JPopupMenu show is called