Pramod Yadav
Pramod Yadav

Reputation: 245

How to disable right click in jxbrowser

I am loading a webpage in jxbrowser in java swing, I want to block or disable right click on that page, I searched but not got the answer, please let me know if any one has any suggestion.

Thanks

Upvotes: 0

Views: 391

Answers (2)

Ben Crowhurst
Ben Crowhurst

Reputation: 8481

The latest JxBrowser has major API changes. If you are using 7.* or above the approach is as follows.

browser.set(MoveMouseWheelCallback.class, params -> Response.suppress());

Available Callbacks

  • EnterMouseCallback
  • ExitMouseCallback
  • MoveMouseCallback
  • MoveMouseWheelCallback
  • PressKeyCallback
  • PressMouseCallback
  • ReleaseKeyCallback
  • ReleaseMouseCallback
  • TypeKeyCallback

Links

What's New

API Documentation

Upvotes: 1

Pramod Yadav
Pramod Yadav

Reputation: 245

After a long search, finally I have a working solution for disabling right click

final Browser browser = new Browser();
        BrowserView view = new BrowserView(browser);


view.setMouseEventsHandler(new InputEventsHandler<MouseEvent>() {           
        @Override
        public boolean handle(MouseEvent arg0) {                
            if(arg0.getButton() == MouseEvent.BUTTON3)
                return true;
            return false;
        }
    });

Upvotes: 1

Related Questions