Exception while trying to hide the browser

Having problems with building or using the JCEF Java binding? Ask your questions here.

Exception while trying to hide the browser

Postby ramyakrishnan » Mon Sep 28, 2015 1:12 pm

So , I have an operation where I hide and unhide the browser using Javascript on a button click event. I have some pictures positioned at specific coordinates put on top of my HTML page that I load. So whenever I hide the browser, it is throwing me this exception: java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location
at java.awt.Component.getLocationOnScreen_NoTreeLock(Component.java:2048)
at java.awt.Component.getLocationOnScreen(Component.java:2022)
at org.cef.browser.CefBrowserOsr.getScreenPoint(CefBrowserOsr.java:248)
at org.cef.CefClient.getScreenPoint(CefClient.java:769)

How do I hide the browser correctly, so that I dont see this exception ?
I see the renderer handler is getting called every time and that is causing this exception.
Currently I just do browserPanel.setVisible(false) to hide the browser and browserPanel.setVisible(true) to show it , is this the right way ?
ramyakrishnan
Mentor
 
Posts: 62
Joined: Wed Sep 16, 2015 12:21 pm

Re: Exception while trying to hide the browser

Postby ramyakrishnan » Tue Sep 29, 2015 1:13 pm

Any pointers on this exception I am getting ?
ramyakrishnan
Mentor
 
Posts: 62
Joined: Wed Sep 16, 2015 12:21 pm

Re: Exception while trying to hide the browser

Postby ramyakrishnan » Tue Sep 29, 2015 2:39 pm

I figured the error is because of this method in the CefBrowserOsr.java code :

Code: Select all
 @Override
  public Point getScreenPoint(CefBrowser browser, Point viewPoint) {
          Point screenPoint = canvas_.getLocationOnScreen();
          screenPoint.translate(viewPoint.x, viewPoint.y);
          return screenPoint;      
  }


but when i hide the panel, the canvas is not visible for the program to get the getLocationOnScreen() value . So I made a small tweak to this method,( I donno how correct is this approach . Please comment on my solution for this.


Code: Select all
 @Override
  public Point getScreenPoint(CefBrowser browser, Point viewPoint) {
     try{
          Point screenPoint = canvas_.getLocationOnScreen();
          screenPoint.translate(viewPoint.x, viewPoint.y);
          return screenPoint;
         }
         catch(Exception e){
            return null;
         }
  }
ramyakrishnan
Mentor
 
Posts: 62
Joined: Wed Sep 16, 2015 12:21 pm

Re: Exception while trying to hide the browser

Postby JavaProgramer » Sat Nov 07, 2015 5:24 pm

JavaProgramer
Newbie
 
Posts: 8
Joined: Sat Nov 30, 2013 10:05 am


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 27 guests