Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to apply my custom css rule to a JavaFX Web Browser?

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have cross-posted my post to Oracle Community Forums
I asked the question before four days and I have no reply.
I have read the rules about cross-posting : Be Forthright when Cross Posting To Other Sites
Oracle forum is also informed about cross-posting.
I would appreciate any reply.

I want to apply my css rule to specific nodes of WebView.
I use Node.lookupAll(String cssSelector) method to find the node and Node.setStyle(String ccsStyle) to apply my rules.
As an example I use the following code from JavaFX Documentation










 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
WebEngine.load() does not wait until loading has completed. That means if you try to access the web page DOM immediately after load() returns, the page is incompletely loaded.
The right way to do it is to access the DOM after the page has completed loading. The component notifies completion via a listener. It should look like this (from WebEngine documentation):


The other problem in your code is the line:

This code does not find "body" elements in the web page loaded in WebEngine. Instead, what it does is look for a "body" element in the scene's object graph.
When a WebEngine loads a web page, it does not convert the HTML elements in web page into JavaFX Nodes.

One correct way to do what you want is:

 
Constantine Mosch
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Karthik Shiraly
Wow!!!
I didn' t expect a so detailed response.Thank you for taking the time to write.
I still have a problem.
I use Jsoup library and I use CSS selectors to find DOM elements.
w3c.dom.Document doesn't support CSS selector and finds elements by id or by tagName

How do I find elements in a w3c.dom.Document using CSS rules (like Jsoup document )?
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> I use Jsoup library and I use CSS selectors to find DOM elements.

Jsoup has it's own Document model class and does not provide a way to directly translate a w3c document model to it's document model. Also it's APIs only function on it's internal jsoup document model, not the w3c document model supported by WebView. So I do not believe that you would want to use Jsoup in conjunction with a WebView - they aren't really compatible.

> How do I find elements in a w3c.dom.Document using CSS rules (like Jsoup document )?

I would advise using jQuery and working directly against the dom model via the WebView's JavaScript engine rather than working in Java against the Java w3c document model. There is a sample for this in this gist.
 
Constantine Mosch
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@John Damien Smith
Thanks for your reply.
executejQuery() method works fine.

I have another problem.
In the code below, I have disable javascript because JavaFX WebEngine crashes
when loads some web pages eg http://www.protothema.gr/
Before I call executejQuery(engine, script), I call engine.setJavaScript(true)

I must press JButton "Change" twice to change tag <a> font color.
How can I fix this problem?
 
Happily living in the valley of the dried frogs with a few tiny ads.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic