简体   繁体   English

在Java中嵌入HTML文件

[英]Embed HTML file in Java

I am trying to put an offline Openstreetmap map into my Java Application. 我正在尝试将离线Openstreetmap映射放入Java应用程序。 I have found an example here: http://www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html 我在这里找到了一个示例: http : //www.apl.jhu.edu/~hall/java/Swing-Tutorial/Swing-Tutorial-JEditorPane.html

However when I tried to change the URL in the program to the file that is in my computer, it did not work. 但是,当我尝试将程序中的URL更改为计算机中的文件时,它无法正常工作。 The HTML page that I am trying to display has JavaScript and I think this is why it will not appear. 我要显示的HTML页面具有JavaScript,我认为这就是为什么它不会出现的原因。 (I tried displaying a different HTML which was more simple and only had an image to display and it worked.) (我尝试显示另一个HTML,该HTML更简单,并且只显示图像并且可以正常工作。)

Is there a way to embed an HTML file in a Java Application that supports JavaScript? 有没有办法在支持JavaScript的Java应用程序中嵌入HTML文件? Or is something else preventing the application from displaying my HTML file? 还是其他原因阻止了应用程序显示我的HTML文件?

edit: I am trying to embed an HTML file with an OpenLayers Javascript. 编辑:我正在尝试使用OpenLayers Javascript嵌入HTML文件。 I have come across the Lobo Browser, it seems like what I am looking for. 我遇到过Lobo浏览器,好像是我要找的东西。 However when I try to visit a site in the browser, it only show's me a blank page. 但是,当我尝试在浏览器中访问网站时,它只会显示空白页面。 I am sure that my Java is updated. 我确定我的Java已更新。 Has anyone had experience with the Lobo Browser and have an idea as to why it is not working for me? 有没有人曾经使用过Lobo浏览器,并且对为什么它不适合我有一个想法?

You can try JavaFX. 您可以尝试JavaFX。 I found some nice alternatives that I'm willing to try here: 我找到了一些我愿意在这里尝试的不错的选择:

Is there a way to embed an HTML file in a Java Application that supports JavaScript? 有没有办法在支持JavaScript的Java应用程序中嵌入HTML文件?

Possibly by embedding support for the the Rhino engine or the ScriptEngine into the HTMLEditorKit . 可能通过将对Rhino引擎ScriptEngine支持嵌入HTMLEditorKit

Note that I have considered trying to do that myself, but since it seems like a lot of effort for little chance of success, I always avoided doing so. 请注意,我已经考虑过自己尝试这样做,但是由于似乎付出了很大的努力却几乎没有成功的机会,所以我始终避免这样做。

As per this reply : 根据此答复

JEditorPane has limited html and css support. JEdi​​torPane具有有限的html和css支持。 It does not support javascript or applets. 它不支持javascript或applet。

An alternate solution suggested is trying to embed Gecko in your application. 建议的替代解决方案是尝试将Gecko嵌入您的应用程序。

I suppose that shouldnot be a problem. 我想那应该不是问题。 It wud be helpful if you could paste the code in that file you are pointing to(the one containing javascript that you suspect is not working). 如果您可以将代码粘贴到您指向的文件中(怀疑其中包含javascript的代码无法正常工作),那将很有帮助。

I have found this similar question: Embed a web browser within a java application 我发现了类似的问题: 在Java应用程序中嵌入Web浏览器

There are many different answers there. 那里有许多不同的答案。 Mozswing worked for me: http://sourceforge.net/projects/mozswing/ Mozswing为我工作: http : //sourceforge.net/projects/mozswing/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM