This week's book giveaway is in the General Computing forum. We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line! See this thread for details.
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?
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
// 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) {
// 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.