Last active
March 27, 2018 17:16
-
-
Save alamenai/68e192c6d4708ef3e1d305f9d5df2f3b to your computer and use it in GitHub Desktop.
JavaFx example to make a changes in html file and reload it again in webview.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void reloadContent() | |
{ | |
//Using Jsoup library https://jsoup.org/cookbook/introduction/parsing-a-document | |
//Get html file | |
InputStream inputStream = Odata.class.getClass().getResourceAsStream("/web/html/template.html"); | |
//Parse the content | |
org.jsoup.nodes.Document doc = Jsoup.parse(inputStream, "UTF-8", ""); | |
//Get Element for make some changes | |
org.jsoup.nodes.Element content = doc.getElementById("name"); | |
//Change the text of element | |
content.text("Menai Ala Eddine"); | |
//Get image element | |
Element image = doc.getElementById("profile-image"); | |
//Change relative path in jar file | |
//The original path in html file :src="../../appimages/images/male-user-profile-picture.png" | |
image.attr("src",getClass().getResource("/appimages/images/male-user-profile-picture.png").toExternalForm()); | |
WebView browser = new WebView(); | |
WebEngine webEngine = browser.getEngine(); | |
//Load the new content after make changing | |
webEngine.loadContent(doc.html()); | |
webEngine.setUserStyleSheetLocation(getClass().getResource("/web/stylesheets/inscription_template.css").toString()); | |
Stage embeddedStage = new Stage(); | |
StackPane pane = new StackPane(browser); | |
Scene embeddedScene = new Scene(pane, 500, 500); | |
embeddedStage.setScene(embeddedScene); | |
embeddedStage.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Answer of these questions in StackOverFlow :