Solved

JPopupMenu....

Posted on 1998-09-23
2
590 Views
Last Modified: 2008-02-26
I am using the JPopupMenu in response to a button being pressed.  The popup menu shows when I press the button, but if I move the frame which the test app sits in, the popup menu disappears.  Why is this and how can I fix it?
0
Comment
Question by:beemer
2 Comments
 
LVL 2

Expert Comment

by:shchuka
ID: 1224879
I think this is how popup menus behave - they disapper if you move the frame.  Thus you can't really do anything to keep it open.  On the other hand, you can simulate this behavior by declaring some boolean variable that is equal to true if the menu is open and is set to false when it's closed.  Now, when you do something which might close the menu, in that event check whether this variable is set and if yes, open the menu.
0
 
LVL 3

Accepted Solution

by:
sailwind earned 50 total points
ID: 1224880
Popup menus will only appear when you click on the item that generates the
popup menu. When you click on another component, Java assumes that you
no longer want to work with the popup menu and therefore closes it. This is
the way normal windows work. For example, if you pull down the file menu,
but click somewherelse on the screen before making the selection, the file
menu will close since it assumes you don't want it anymore. Same concept.

When you move the window, java takes this as a sign that you want to
interact with the frame now, not the popup menu, and will therefore close the
popup menu.

What you can do is add a componentListener to your window. In your listener,
define the method componentMoved() to pop up the popupmenu if it is needed.
You can use a simple boolean flag like shchuka suggested.

Hope this helped!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This video teaches viewers about errors in exception handling.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now