File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Unrelenting JPopupMenu Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Unrelenting JPopupMenu" Watch "Unrelenting JPopupMenu" New topic

Unrelenting JPopupMenu


Joined: Feb 02, 2001
Posts: 5
I have a JPopupMenu that appears in various places on the desktop. If it comes up as a result of right clicking an icon, I want that menu to become invisible if the user clicks off the menu. The trouble is that it stays up unless a menuitem is selected. This causes no end of interference with other popup menus that my app also makes appear. Is this behavior a bug in the JDK (1.3)? Is there a workaround?
Brett Spell
Ranch Hand

Joined: Feb 24, 2001
Posts: 107
No, what you've described is not the normal behavior of a JPopupMenu. Could you post the code snippet that you're using to make the popup menu appear?
Brett Spell
Author, Professional Java Programming

Joined: Feb 02, 2001
Posts: 5
Here is the requested snippet.

// In the application startup code we add a JComponent to the main DeskBar
// which is actually a JWindow that appears as a TaskBar-like entity.
m_mainDeskBar.addJComponent(new FabCentricMenuBtn(m_mainDeskBar, this));
// Here is the declaration of the DeskBar class:
public class DeskBar extends JWindow
implements SwingConstants,AppBarIndicatorListener
// Here is some of the code for the menu button that exhibits the odd
// unrelenting behavior.
public class FabCentricMenuBtn extends JButton implements
private JPopupMenu m_appPopupMenu;
private JMenuItem m_menuStatusFreq;
private JMenuItem m_menuOptions;
private JMenuItem m_menuBackdrop;
private JMenuItem m_menuAbout;
private JMenuItem m_menuExit;
private JMenuItem m_menuLanguages;
public FabCentricMenuBtn(DeskBar parent, YieldNavigator yn)

m_appPopupMenu = new JPopupMenu();

// code to set up the menuitems and their actions.
public void actionPerformed(final java.awt.event.ActionEvent event)

if (event.getSource() == m_menuExit)
// don't just exit, need to cleanup the appbar and so on.

if (event.getSource() == this)
// show the menu
// where am I?
Dimension d = getSize();
//m_yieldNavApp.hideContextMenu();, 0, d.height);
I agree. Here's the link:
subject: Unrelenting JPopupMenu
It's not a secret anymore!