java cef3 禁止右键菜单项

时间:2024-01-10 08:07:08

如下图所示,在context_menu_handler.cpp中ContextMenuHandler::OnBeforeContextMenu添加以下代码即可:

  if (model->GetCount() > ){
model->Clear();
}

java cef3 禁止右键菜单项

暂时没有找到如何在java代码里去干这件事情,如果有朋友知道的话,麻烦留言告知在下,感激不尽!


补:

经过这几天对JCEF的学习,终于找到了如何在java代码中去禁止右键菜单

public class ContextMenuHandler implements CefContextMenuHandler {

    private final Frame owner;

    private Map<Integer, String> suggestions = new HashMap<Integer, String>();

    public ContextMenuHandler(Frame owner) {
this.owner = owner;
} @Override
public void onBeforeContextMenu(CefBrowser browser, CefContextMenuParams params, CefMenuModel model) {
model.clear();
} @Override
public boolean onContextMenuCommand(CefBrowser browser, CefContextMenuParams params, int commandId,
int eventFlags) {
return false;
} @Override
public void onContextMenuDismissed(CefBrowser browser) { } }

实现CefContextMenuHandler 接口的实现类,然后在onBeforeContextMenu方法中model.clear(),然后在主界面的CefClient对象中加入该实现即可

client = myApp.createClient();
client.addContextMenuHandler(new ContextMenuHandler(this));

如果要修改右键菜单项,可以点击看我另一篇随笔:JCEF 如何修改右键菜单项