?
Solved

JPopupMenu....

Posted on 1998-09-23
2
Medium Priority
?
609 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 100 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
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…
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:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses
Course of the Month7 days, 21 hours left to enroll

765 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