Solved

JPopupMenu....

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
simple java question 3 59
more than one jdk and one jre 1 50
SHA2 certs for IIS AND Java? 2 113
printf performancy 11 70
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

861 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