Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2005

Tip: Looking for answers? Try searching our database.

MouseEvent problem in JPopupMenu

Thread view: 
Chris Smith - 27 Jan 2005 07:09 GMT
I'm having trouble getting a MouseEvent to get fired for mouseReleased
to fire in any component added to a submenu of a JPopupMenu in Java 1.5.  
The same code works fine in 1.4.

Here's some simple code to demonstrate the problem.  When clicking the
final button, it stays down and "released" is never printed by the
listener.  Under 1.4, the button is fully operational, and "released" is
printed.  The other two events (clicked and pressed) work fine in either
version.

Any ideas what's going on here?  Any suggested work-arounds?  The real
application where I observed this has a rather complex custom component
placed in a submenu of a JPopupMenu, and mouseReleased is needed for it
to work properly.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JPopupMenu;

public class BugTest extends JFrame
{
   private MouseListener ml = new MouseListener() {
       public void mouseEntered(MouseEvent e) { }
       public void mouseExited(MouseEvent e) { }

       public void mouseClicked(MouseEvent e)
       {
           System.out.println("clicked");
       }

       public void mousePressed(MouseEvent e)
       {
           System.out.println("pressed");
       }

       public void mouseReleased(MouseEvent e)
       {
           System.out.println("released");
       }
   };

   public BugTest()
   {
       super("Test Popup mouseReleased");

       JButton startButton = new JButton("Start");

       startButton.addActionListener(new ActionListener() {
           public void actionPerformed(ActionEvent e)
           {
               JPopupMenu popup = new JPopupMenu();
               JMenu middleMenu = new JMenu("Middle");
               JButton endButton = new JButton("End");

               endButton.addMouseListener(ml);

               middleMenu.add(endButton);
               popup.add(middleMenu);
               popup.show(BugTest.this, 20, 20);
           }
       });

       getContentPane().add(startButton);
       pack();
       setVisible(true);
   }

   public static void main(String[] args)
   {
       new BugTest();
   }
}

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation

Chris Smith - 28 Jan 2005 21:34 GMT
> I'm having trouble getting a MouseEvent to get fired for mouseReleased
> to fire in any component added to a submenu of a JPopupMenu in Java 1.5.  
> The same code works fine in 1.4.

Update: at least someone from Sun thinks this is a bug, and it's now in
Bug Parade at

   http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6222765

Nevertheless, I'd still be very appreciative if someone knows of a work-
around.

Signature

www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.