我希望能够从Internet加载HTML文档,将其显示在JEditorPane中,并使用外部CSS文件和/或任何<style>...</style>
标记在Java中设置样式。我现在正在做的是使用jEditorPane.setPage(URL);
并且它没有正确设置风格。
答案 0 :(得分:3)
基于JavaDoc - jEditorPane支持前沿 HTML 3.2和CSS1所以简短的回答是,你真的不想尝试渲染现代网页它
但是,您可以这样做:
import javax.swing.text.html.HTMLEditorKit;
import javax.swing.text.html.StyleSheet;
HTMLEditorKit kit = new HTMLEditorKit();
jEditorPane.setEditorKit(kit);
URL url = new URL(location of your stylesheet);
StyleSheet styleSheet = new StyleSheet();
styleSheet.importStyleSheet(url)
kit.setStyleSheet(styleSheet);
答案 1 :(得分:1)