Blocking / Disabling JavaFX 2 WebView
For the record only, it is implemented in JavaFX 2.2. See the documentation for setContextMenuEnabled
source to share
I came up with a working, but ugly, inelegant and, I would say, guerrilla solution, which I don't really like, but I don't really have (or just can't find) any other way out.
It includes a modification to the EventDispatcher WebView.
So my EventDispatcher implementation needs a reference to the original WebView EventDispatcher and looks like this:
public class MyEventDispatcher implements EventDispatcher {
private EventDispatcher originalDispatcher;
public MyEventDispatcher(EventDispatcher originalDispatcher) {
this.originalDispatcher = originalDispatcher;
}
@Override
public Event dispatchEvent(Event event, EventDispatchChain tail) {
if (event instanceof MouseEvent) {
MouseEvent mouseEvent = (MouseEvent) event;
if (MouseButton.SECONDARY == mouseEvent.getButton()) {
mouseEvent.consume();
}
}
return originalDispatcher.dispatchEvent(event, tail);
}
}
Each event is dispatched through our dispatcher and I check if it clicked correctly. If this I just destroy and continue on.
To do this, you must use a WebView like this:
WebView webView = new WebView();
EventDispatcher originalDispatcher = webView.getEventDispatcher();
webView.setEventDispatcher(new MyEventDispatcher(originalDispatcher));
Every comment, hint, etc. are evaluated.
source to share
You can flatten the context menus using the following css.
.context-menu { -fx-background-color: transparent; }
.menu-item { -fx-background-color: transparent; }
.menu-item .label { -fx-text-fill: transparent; }
.menu-item:show-mnemonics .mnemonic-underline { -fx-stroke: -transparent; }
This will make all context menus and menu items transparent. I am not sure about the css selector you can use so this only applies to WebView context menus. If you don't have any other menus in your app, it might not matter.
source to share
Unfortunately, this is not yet possible. There is a feature request for this that you can track: http://javafx-jira.kenai.com/browse/RT-15684
source to share