This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to make JPopupMenu invisible? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to make JPopupMenu invisible?" Watch "How to make JPopupMenu invisible?" New topic

How to make JPopupMenu invisible?

Andrei Mura

Joined: Nov 26, 2009
Posts: 18
I have added to a JTextField a JPopupMenu.
Unfortunatelly, when i change the focus from JTextField, or when i "minimize" the window, the JPopupMenu still is visible.
I need to make it invisible if JTextField is loosing the focus.
How can i do this?
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2372
I guess you can add a FocusListener to the text field. When the focusLost() event is fired you get the source which will be the text field and then get the parent which should be the popup menu which you can then hide manually.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2372
Cross post:

Good to know I wasted my time answering a question that has already been answered. That won't happen again.

Rob Spoor

Joined: Oct 27, 2005
Posts: 20077

What Rob was referring to is

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: How to make JPopupMenu invisible?
It's not a secret anymore!