Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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] Fri, 05 February 2010 04:47 Go to next message
Anakkapan K. is currently offline Anakkapan K.Friend
Messages: 11
Registered: February 2010
Junior Member
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 16:57 Go to previous message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
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: Fri Mar 29 01:24:33 GMT 2024

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

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

Back to the top