Note that there are some explanatory texts on larger screens.

plurals
  1. POMouseListener for JPanel missing mouseClicked events
    text
    copied!<p>I have a JPanel that I have created a MouseListener for and I am seeing some behavior that I can't explain. </p> <p>Usually when I click the mouse within the JPanel, I see the following events fire:</p> <pre><code>mousePressed mouseReleased mouseClicked </code></pre> <p>On some occasions, I don't see the mouseClicked event fire, I only see:</p> <pre><code>mousePressed mouseReleased </code></pre> <p>I don't think I'm doing anything out of the ordinary when I click these times. Could anyone explain why I might not be seeing the mouseClicked event?</p> <p>I'm not sure if it's relevant, but I do have an animation running in the panel using a javax.swing.Timer.</p> <p>Any help is appreciated.</p> <p><strong>EDIT:</strong> adding test code that replicates problem. I'm not sure, but I wonder if my mouse has anything to do with it. I have one of those super sensitive gaming mice (from my old COD4 days).</p> <pre><code>import java.awt.Color; import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JFrame; import javax.swing.JPanel; public class Test { public static void main(String[] args) { final Test test = new Test(); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { test.createAndShowGUI(); } }); } protected void createAndShowGUI() { JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(1024, 768)); frame.setTitle("Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); panel.setBackground(Color.WHITE); panel.addMouseListener(new MouseListener() { @Override public void mouseReleased(MouseEvent e) { System.out.println(":MOUSE_RELEASED_EVENT:"); } @Override public void mousePressed(MouseEvent e) { System.out.println("----------------------------------\n:MOUSE_PRESSED_EVENT:"); } @Override public void mouseExited(MouseEvent e) { System.out.println(":MOUSE_EXITED_EVENT:"); } @Override public void mouseEntered(MouseEvent e) { System.out.println(":MOUSE_ENTER_EVENT:"); } @Override public void mouseClicked(MouseEvent e) { System.out.println(":MOUSE_CLICK_EVENT:"); } }); frame.add(panel); frame.pack(); frame.setVisible(true); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload