Solved

JPopupMenu....

Posted on 1998-09-23
2
593 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
network + 7 80
maven project error 5 48
stackato and cloud 4 74
eclipse apache tomcat admin console 52 73
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

867 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

17 Experts available now in Live!

Get 1:1 Help Now