Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT Browser loss its focus when Browser.evaluate() is called
SWT Browser loss its focus when Browser.evaluate() is called [message #512426] Thu, 04 February 2010 23:47 Go to next message
Eclipse UserFriend
I open an editor, which is an html page, on SWT Browser. When I want to get data from it, I use Browser.evaluate() to obtain the data from editor using javaScript. But the editor then loss a focus every time I try to get its data. Is it any way to solve this problem?

PS. I tried evaluate other function on that editor page and it loss its focus every time evalute() is called.
Re: SWT Browser loss its focus when Browser.evaluate() is called [message #513062 is a reply to message #512426] Mon, 08 February 2010 11:57 Go to previous message
Eclipse UserFriend
Hi,

This should not happen, and I don't see it happen with the snippet below
(tried with IE6- and XULRunner-based Browsers on Windows 2000). If you run
the snippet and give focus to the page's text control does it lose focus
when the timer expires after 5s? And which platform and native browser are
you using?

public static void main(String [] args) {
Device.DEBUG = true;
final String html = "<html><title>Snippet</title><body><p id='myid'>Best
Friends</p><p id='myid2'>Cat and Dog</p><textarea rows=\"2\"
cols=\"20\">hi</textarea></body></html>";
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout());
final Browser browser;
try {
browser = new Browser(shell, SWT.NONE);
} catch (SWTError e) {
System.out.println("Could not instantiate Browser: " +
e.getMessage());
display.dispose();
return;
}
browser.setLayoutData(new GridData(200,200));
browser.addProgressListener(new ProgressListener() {
public void changed(ProgressEvent event) {}
public void completed(ProgressEvent event) {
display.timerExec(5000, new Runnable() {
public void run() {
String value = (String)browser.evaluate("return
document.getElementById('myid').childNodes[0].nodeValue;");
System.out.println("Node value: "+value);
}
});
}
});
new Text(shell, SWT.SINGLE); // <--- I do nothing

browser.setText(html);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}

Grant


"Anakkapan K." <knock_kknd@hotmail.com> wrote in message
news:hkg7ud$2r1$1@build.eclipse.org...
> I open an editor, which is an html page, on SWT Browser. When I want to
get data from it, I use Browser.evaluate() to obtain the data from editor
using javaScript. But the editor then loss a focus every time I try to get
its data. Is it any way to solve this problem?
>
> PS. I tried evaluate other function on that editor page and it loss its
focus every time evalute() is called.
Previous Topic:How to scroll down the vertical bar?
Next Topic:How can I get private data out of StyledText?
Goto Forum:
  


Current Time: Sun Jul 06 09:19:26 EDT 2025

Powered by FUDForum. Page generated in 0.03743 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top