aspose file tools*
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
Author

Unrelenting JPopupMenu

JeffreyTucker
Greenhorn

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: 54
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


Brett Spell<BR>Author, <B><A HREF="http://www.amazon.com/exec/obidos/ASIN/186100382X/ref=ase_electricporkchop/105-8609264-3147921" TARGET=_blank >Professional Java Programming</A></B>
JeffreyTucker
Greenhorn

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
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);
}
}
}
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unrelenting JPopupMenu
 
Similar Threads
JPopupMenu
Jpopupmenu in Jtreetable
JPopUp
JMenuItem centering
Copy and paste popup menu