本文介绍了如何从 javafx.scene.web.WebEngine#loadContent 加载的 html 页面访问 css 和图像文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串 HTML 内容,它通过 loadContent() 方法加载到 webEngine 中.我也在这个页面中使用了一些 css 和图像文件.虽然我把这些文件放在同一个java类的包中,但是加载的页面找不到它们.寻找 API 文档和网络,但找不到任何合适的类似解决方案.我如何加载这些文件?

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 和图像文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 12:55
查看更多