www.teamdev.com

This Question is Possibly Answered

1 "correct" answer available (4 pts) 1 "helpful" answer available (2 pts)
3 Replies Last post: Aug 5, 2008 11:44 AM by Vladimir Ikryanov  
Click to view kengentry5001's profile   3 posts since
Jul 31, 2008

Aug 1, 2008 2:55 PM

Child window sizing and crash on screen capture (Repost as question)


Sorry for the duplicate post but forgot to post this as a question...


I am using JExplorer 1.9, Windows XP Pro, IE7, JDK 1.5.0_14 and Adobe Acrobat Reader v8.0.

My browser automation app clicks a link to a PDF file. A new child window pops up that needs to be resized (can't even see any content). I want to resize the window so the PDF is viewable and then take a screenshot. When I resize the window using:
child.getgetTopLevelAncestor().setBounds(0, 0, 1000, 800);

The resize works but the window does not repaint the PDF content - just get a gray colored empty window. I tried adding a child.refresh() but it didn't work. If I put in a sleep after the child pops up I can manually resize the window and it repaints the PDF properly. Is there a way to specify a window size for children BEFORE they are opened? This would be very helpful rather than resizing after the window is opened.

Another problem is I get a NullPointerException when I try to take a screenshot of this window:

Exception in thread "main" java.lang.NullPointerException
at com.jniwrapper.win32.ie.dom.e.getElementsByTagName(SourceFile:233)
at com.jniwrapper.win32.ie.dom.e.b(SourceFile:461)
at com.jniwrapper.win32.ie.dom.e.getBody(SourceFile:479)
at com.jniwrapper.win32.ie.dom.e.c(SourceFile:528)
at com.jniwrapper.win32.ie.dom.e.getHorisontalScrollPosition(SourceFile:552)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.jniwrapper.win32.ie.dom.j.run(SourceFile:592)
at com.jniwrapper.win32.MessageLoopThread$ThreadSynchronizedAction.run(MessageLoopThread.java:569)
at com.jniwrapper.win32.MessageLoopThread$LoopThread.run(MessageLoopThread.java:511)

Any help you can provide to get this working would be greatly appreciated.

Click to view Vladimir Ikryanov's profile TeamDev Ltd. 350 posts since
Apr 24, 2006
1. Aug 4, 2008 6:16 PM in response to: kengentry5001
Re: Child window sizing and crash on screen capture (Repost as question)
Hello,

1. In order to resize child window correctly you need to call the validate() method too. For example:

        browser.addNewWindowListener(new NewWindowEventListener()
        {
            public void windowOpened(WebBrowser webBrowser)
            {
                Container ancestor = ((Browser) webBrowser).getTopLevelAncestor();
                ancestor.setBounds(0, 0, 1000, 800);
                ancestor.validate();
            }
        });


2. The WebBrowser.getScreenShot() method can be used only for making screenshot of a HTML web page. This method is not implemented for taking screenshot of an Acrobat Reader document embedded into Browser component.

Regards,
Vladimir Ikryanov
Click to view Vladimir Ikryanov's profile TeamDev Ltd. 350 posts since
Apr 24, 2006
3. Aug 5, 2008 11:44 AM in response to: kengentry5001
Re: Child window sizing and crash on screen capture (Repost as question)
Hi,

In order to programmatically close child window you need just to dispose its window. For example:

Container ancestor = ((Browser) child).getTopLevelAncestor();
((JFrame) ancestor).dispose();


The reason of NPE you receive is that actually the WebBrowser.close() method is invoked twice. At first you invoke this method directly and then this method is invoked automatically when you press the "X" button on child browser window.

Regards,
Vladimir Ikryanov