java-cef
java-cef copied to clipboard
Mouse Press on Menu Item Publishes Duplicate Events
Describe the bug When embedding a JCEF web view in a Swing application, mouse events on JMenu or JMenuItem components publish duplicate MOUSE_PRESSED events. Due to this, the menu opens and closes immediately, making it difficult to interact with the menu items.
To Reproduce Steps to reproduce the behavior:
- Create a JFrame with a JMenuBar and embed a JCEF web view component.
- Add a MouseListener to the JMenu to log mouse events.
- Click on the menu item (e.g., "File") in the JMenuBar.
- Observe duplicate MOUSE_PRESSED events being published in the console.
public MainFrame(String startURL) throws Exception {
setJMenuBar(createMenuBar());
getContentPane().add(getBrowser(startURL), BorderLayout.CENTER);
setSize(800, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static JMenuBar createMenuBar() {
JMenu myFileMenu = new JMenu();
myFileMenu.setMnemonic('F');
myFileMenu.setText("File");
JMenuItem myOpen = new JMenuItem();
myOpen.setMnemonic('O');
myOpen.setText("Open");
myOpen.addActionListener(e -> System.out.println("Open clicked"));
myFileMenu.add(myOpen);
myFileMenu.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
System.out.println("Mouse pressed: " + e);
}
});
JMenuBar myMenuBar = new JMenuBar();
myMenuBar.add(myFileMenu);
return myMenuBar;
}
private static Component getBrowser(String startURL) throws IOException, UnsupportedPlatformException, InterruptedException, CefInitializationException {
CefAppBuilder builder = new CefAppBuilder();
builder.getCefSettings().windowless_rendering_enabled = true;
CefClient myClient = builder.build().createClient();
CefBrowser myBrowser = myClient.createBrowser(startURL, false, true);
Component myUIComponent = myBrowser.getUIComponent();
myUIComponent.setFocusable(false);
return myUIComponent;
}
public static void main(String[] args) throws Exception {
SwingUtilities.invokeLater(() -> {
try {
new MainFrame("https://google.com/").setVisible(true);
} catch (Exception aE) {
throw new RuntimeException(aE);
}
});
}
Expected behavior Only a single MOUSE_PRESSED event should be published when interacting with the JMenu. The menu should open and remain open until a selection is made or it is closed by user interaction.
Screenshots Example of duplicate MOUSE_PRESSED events being logged:
Mouse pressed: java.awt.event.MouseEvent[MOUSE_PRESSED,(23,12),absolute(23,64),button=1,modifiers=Button1,extModifiers=Button1,clickCount=1] on javax.swing.JMenu[,0,0,42x21,alignmentX=0.0,alignmentY=0.0,border=com.apple.laf.AquaMenuBorder@55612535,flags=392,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],paintBorder=false,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=File]
Mouse pressed: java.awt.event.MouseEvent[MOUSE_PRESSED,(23,12),absolute(23,64),button=1,modifiers=Button1,extModifiers=Button1,clickCount=1] on javax.swing.JMenu[,0,0,42x21,alignmentX=0.0,alignmentY=0.0,border=com.apple.laf.AquaMenuBorder@55612535,flags=392,maximumSize=,minimumSize=,preferredSize=,defaultIcon=,disabledIcon=,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=0,left=0,bottom=0,right=0],paintBorder=false,paintFocus=false,pressedIcon=,rolloverEnabled=false,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=File]
Versions (please complete the following information):
- OS: Apple M1 Max, 14.5
- Java Version: OpenJDK 21.0.1
- JCEF Version: jcefmaven: 127.3.1
- CEF Version: 127.0.6533.100
Additional context
- The issue is reproducible only when the JCEF web view is embedded in the Swing application. Without the JCEF component, only a single MOUSE_PRESSED event is published.
- The application was run from IntelliJ IDEA using the following command:
/opt/homebrew/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home/bin/java -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:50036,suspend=y,server=n --add-opens java.desktop/sun.lwawt.macosx=ALL-UNNAMED --add-opens java.desktop/sun.lwawt=ALL-UNNAMED --add-opens java.desktop/sun.awt=ALL-UNNAMED -javaagent:/Users/ipatil/Library/Caches/JetBrains/IntelliJIdea2024.2/captureAgent/debugger-agent.jar -Dkotlinx.coroutines.debug.enable.creation.stack.trace=false -Ddebugger.agent.enable.coroutines=true -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath /Users/ipatil/IdeaProjects/JavaCEF/JavaCEF/target/classes:/Users/ipatil/.m2/repository/me/friwi/jcefmaven/127.3.1/jcefmaven-127.3.1.jar:/Users/ipatil/.m2/repository/me/friwi/jcef-api/jcef-99c2f7a+cef-127.3.1+g6cbb30e+chromium-127.0.6533.100/jcef-api-jcef-99c2f7a+cef-127.3.1+g6cbb30e+chromium-127.0.6533.100.jar:/Users/ipatil/.m2/repository/me/friwi/jogl-all/v2.4.0-rc-20210111/jogl-all-v2.4.0-rc-20210111.jar:/Users/ipatil/.m2/repository/me/friwi/gluegen-rt/v2.4.0-rc-20210111/gluegen-rt-v2.4.0-rc-20210111.jar:/Users/ipatil/.m2/repository/org/apache/commons/commons-compress/1.21/commons-compress-1.21.jar:/Users/ipatil/.m2/repository/com/google/code/gson/gson/2.10/gson-2.10.jar:/Applications/IntelliJ IDEA.app/Contents/lib/idea_rt.jar swing.MainFrame
- The issue persists with
windowless_rendering_enabledset to both true and false.