• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unrelenting JPopupMenu

 
JeffreyTucker
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeffrey,
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
 
JeffreyTucker
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
ActionListener
{
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.
//...
m_appPopupMenu.add(m_menuStatusFreq);
m_appPopupMenu.add(m_menuOptions);
m_appPopupMenu.add(m_menuLanguages);
m_appPopupMenu.add(m_menuBackdrop);
m_appPopupMenu.add(m_menuAbout);
m_appPopupMenu.addSeparator();
m_appPopupMenu.add(m_menuExit);
addActionListener(this);
}
public void actionPerformed(final java.awt.event.ActionEvent event)
{
System.out.println(event);

if (event.getSource() == m_menuExit)
{
m_yieldNavApp.cleanup();
// don't just exit, need to cleanup the appbar and so on.
System.exit(0);
}

if (event.getSource() == this)
{
// show the menu
// where am I?
Dimension d = getSize();
//m_yieldNavApp.hideContextMenu();
m_appPopupMenu.show(this, 0, d.height);
}
}
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic