JTextPane shows color different from browser of an HTML

我们两清 提交于 2019-12-11 05:32:50

问题


I am loading a simple HTML page in JTextPane which is showing different color than when viewed in a browser, and also the div tag's height and width are changed.

the HTML file has 1 div tag only nd that is:

<div height ="200" width="100" style="background-color:#0F9">this the div tag  </div>

I am simply calling setPage for JTextPane.

This is how it is displayed in the JTextPane

This is how it should be dislplayed(it is from firefox)


回答1:


I just ran into the same problem. As documented here (http://docs.oracle.com/javase/6/docs/api/javax/swing/text/html/CSS.html), you can use background-color. The value of it has to contain 7 characters, for example

background-color:#00FF99;




回答2:


I think thats because JTextpane doesnt support css.

Edit: try something like this

<div height ="200" width="100" bgcolor="Silver">this the div tag  </div>


来源:https://stackoverflow.com/questions/9615991/jtextpane-shows-color-different-from-browser-of-an-html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!