本文介绍了如何从javafx.scene.web.WebEngine #loadContent加载的html页面中获取css和图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个String HTML内容,它由 loadContent()
方法加载到 webEngine
中。我还有一些在此页面中使用的CSS和图像文件。虽然我把这些文件放在java类的同一个包中,但是加载的页面找不到它们。寻找API文档和Web,但找不到任何适合的类似解决方案。我如何加载这些文件?
I have a String HTML content which is loaded into webEngine
by loadContent()
method. I have also some css and image files used in this page. Although I put these file into the same package of java class, the loaded page cannot find them. Looked for API docs and web, but could not find any appropiate similar solutions. How I load these files?
推荐答案
您需要在html字符串中设置本地路径 loadContent
下一步:
You need to set your local paths in html string for loadContent
next way:
view.getEngine().loadContent(
"<img src='" + getClass().getResource("1.jpg") + "' />");
这篇关于如何从javafx.scene.web.WebEngine #loadContent加载的html页面中获取css和图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!