Skip to content

MouseListener does not work on Windows after hide/show #368

@magreenblatt

Description

@magreenblatt

Original report by Anton Tarasov (Bitbucket: Anton Tarasov).


MS Windows. JCEF 81.2.24+gc0b313d+chromium-81.0.4044.113

The test is modified to print mouse (motion) events on the browser UI component. Also the “Hide and show” menu item hides and shows the browser component.

  1. Run the test.
  2. Keep moving mouse over the browser - see the mouse events printed.
  3. Select from the menu: Tests > Hide and show
  4. Repeat the 2nd step - see the mouse events no longer printed.
diff --git a/java/tests/detailed/MainFrame.java b/java/tests/detailed/MainFrame.java
index [c54b466 (bb)](https://bitbucket.org/chromiumembedded/java-cef/commits/c54b466)..d5e570d [100644 (bb)](https://bitbucket.org/chromiumembedded/java-cef/commits/100644)
--- a/java/tests/detailed/MainFrame.java
+++ b/java/tests/detailed/MainFrame.java
@@ -24,6 +24,8 @@ import java.awt.BorderLayout;
 import java.awt.KeyboardFocusManager;
 import java.awt.event.FocusAdapter;
 import java.awt.event.FocusEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 import java.io.File;
 import java.lang.Thread.UncaughtExceptionHandler;
 
@@ -204,6 +206,13 @@ public class MainFrame extends BrowserFrame {
         JPanel contentPanel = createContentPanel();
         getContentPane().add(contentPanel, BorderLayout.CENTER);
 
+        browser.getUIComponent().addMouseMotionListener(new MouseAdapter() {
+            @Override
+            public void mouseMoved(MouseEvent e) {
+                System.out.println(e);
+            }
+        });
+
         // Clear focus from the browser when the address field gains focus.
         control_pane_.getAddressField().addFocusListener(new FocusAdapter() {
             @Override
diff --git a/java/tests/detailed/ui/MenuBar.java b/java/tests/detailed/ui/MenuBar.java
index [3d7a4d1 (bb)](https://bitbucket.org/chromiumembedded/java-cef/commits/3d7a4d1)..0706c9d [100644 (bb)](https://bitbucket.org/chromiumembedded/java-cef/commits/100644)
--- a/java/tests/detailed/ui/MenuBar.java
+++ b/java/tests/detailed/ui/MenuBar.java
@@ -453,6 +453,14 @@ public class MenuBar extends JMenuBar {
         });
         testMenu.add(newwindow);
 
+        JMenuItem hideShow = new JMenuItem("Hide and show");
+        hideShow.addActionListener(e -> {
+            Container parent = browser_.getUIComponent().getParent();
+            parent.remove(browser_.getUIComponent());
+            SwingUtilities.invokeLater(() -> parent.add(browser_.getUIComponent()));
+        });
+        testMenu.add(hideShow);
+
         add(fileMenu);
         add(bookmarkMenu_);
         add(testMenu);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugBug report

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions