my dog learned polymorphism
The moose likes JavaFX and the fly likes Calling Javafx webEngine method 'executeScript' in Java code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Calling Javafx webEngine method Watch "Calling Javafx webEngine method New topic

Calling Javafx webEngine method 'executeScript' in Java code

Imran Kahn

Joined: May 26, 2013
Posts: 2
Hi everyone,

I hope I'll be able to describe my problem correctly.

I am using a Java program to collect JXTA messages and then based on receive messages, add markers at predefined locations on the google maps. I am using JavaFx to display google maps zoomed into the custom location. I have included marker locations in the JavaScript part of the HTML file as functions so the program knows where to place which marker on the google maps, and on its own the JavaFx code works well.

I want to call webEngine.executeScript('myJavaScriptFucntion') inside my Java program. I have a pipeMsgEvent listener for JXTA pipes and as soon as a particular message is received, appropriate webEngine.executeScript('myJavaScriptFucntion') should be called and a marker should be displayed in the map at the run time.

This is my JavaFx code

and in my Java Program I first call

in the main method

and then inside pipeMsgEvent() method I call

When I run the program there is no error, no warning and no exception. The program runs fine with separate window showing google maps, except that when message is received at the JXTA peer, no marker is placed on the google map. (At the moment I have this putMarker method ON for all received messages). I know the messages are being received fine as I print their contents successfully.

To check, if my code works, I placed a button (add marker) in my JavaFx code and called the same putMarker() function in EventHandler for the button. When I click on the button the markers are displayed on the map exactly the way I want them.

So obviously there is an issue when I call putMarker() in my Java program, although I get no error, exception or warning. May be there is another way to do this.

I think when I call MyBrowser.putMarker() method a new instance of MyBrowser is created and call goes to that instance but as this new instance has no display window of its own no output is shown.

May be I am wrong but I hope I have explained my problem, so any suggestion on what should I do to get the markers displayed from the Java code?

-- Regards,

Imran Kahn

Joined: May 26, 2013
Posts: 2
Problem solved. just needed to use Platform.runLater when calling
I agree. Here's the link:
subject: Calling Javafx webEngine method 'executeScript' in Java code
It's not a secret anymore!