<Swing Dev> Mouse click cause MOUSE_EXITED and MOUSE_ENTERED event on macOS

Reto Merz reto.merz at abacus.ch
Wed Apr 12 13:16:11 UTC 2017


Hi,

We have found out that a simple mouse click cause a MOUSE_EXITED and MOUSE_ENTERED on macOS in contrary to Windows.
This happen only when the click is performed on a dialog with a frame (owner) behind it.
It seems that the frame in the background cause the bug.

Steps to reproduce:
    1. start reproducer (source below) -> a frame is opened with a button "Open dialog"
    2. click on "Open dialog" -> a white dialog is opened, this dialog must overlay the frame
    3. click in the white dialog -> see console output

Note that the reproducer logs mouse events to the console
(it might be useful to disable line wrapping in macOS terminal with "rput rmam").

On Windows the click cause this events (as expected): 
    java.awt.event.MouseEvent[MOUSE_PRESSED,(164,113),absolute(1942,763),button=1,modifiers=Button1,extModifiers=Button1,clickCount=1]
    java.awt.event.MouseEvent[MOUSE_RELEASED,(164,113),absolute(1942,763),button=1,modifiers=Button1,clickCount=1]
    java.awt.event.MouseEvent[MOUSE_CLICKED,(164,113),absolute(1942,763),button=1,modifiers=Button1,clickCount=1]

On macOS (10.12.3) the click also cause MOUSE_EXITED and MOUSE_ENTERED:
    java.awt.event.MouseEvent[MOUSE_PRESSED,(130,134),absolute(820,501),button=1,modifiers=Button1,extModifiers=Button1,clickCount=1]
    java.awt.event.MouseEvent[MOUSE_EXITED,(130,134),absolute(820,501),button=0,modifiers=Button1,extModifiers=Button1,clickCount=0]
    java.awt.event.MouseEvent[MOUSE_ENTERED,(130,134),absolute(820,501),button=0,modifiers=Button1,extModifiers=Button1,clickCount=0]
    java.awt.event.MouseEvent[MOUSE_RELEASED,(130,134),absolute(820,501),button=1,modifiers=Button1,clickCount=1]
    java.awt.event.MouseEvent[MOUSE_CLICKED,(130,134),absolute(820,501),button=1,modifiers=Button1,clickCount=1]

Both tested with the latest public Java 8 release (from java.com):
    java -version
        java version "1.8.0_121"
        Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
        Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Why we get an additional MOUSE_EXITED and MOUSE_ENTERED on macOS?
It this a (known) bug or should we report this via bugreport.java.com?

Thanks
Reto

Reproducer:

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.WindowConstants;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.MouseEvent;

public class MouseExited {
  public static void main(String[] args) throws Throwable {
    EventQueue.invokeAndWait(() -> {
      JFrame frame = new JFrame();
      frame.setSize(500, 500);
      frame.setLocationRelativeTo(null);
      frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

      JButton button = new JButton("Open dialog");
      button.addActionListener(e -> {
        JTable table = new JTable() {
          @Override
          protected void processMouseEvent(final MouseEvent e) {
            System.out.println(e.toString());
          }
        };
        JPanel dialogPane = new JPanel(new BorderLayout());
        dialogPane.add(table);
        JDialog dialog = new JDialog(frame);
        dialog.setContentPane(dialogPane);
        dialog.setModal(true);
        dialog.setSize(300, 300);
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
      });

      JPanel framePane = new JPanel(new BorderLayout());
      framePane.add(button);
      frame.setContentPane(framePane);
      frame.setVisible(true);
    });
  }
}





More information about the swing-dev mailing list