Java Swing 中 HTML 的使用与解析
在 Java Swing 编程中, JEditorPane 是一个强大的组件,它可以用来显示和编辑 HTML 内容。下面将详细介绍 JEditorPane 的多种使用方式以及 HTML 解析的相关内容。
1. JEditorPane 构造函数
JEditorPane 有多种构造函数,每种构造函数都有其特定的用途。
- 第三种构造函数 :该构造函数接受一个字符串形式的 URL 作为参数,而不是一个 URL 对象。如果它无法识别协议,可能会抛出 MalformedURLException 。示例代码如下:
try {
JEditorPane jep = new JEditorPane("http://www.oreilly.com/");
jep.setEditable(false);
JScrollPane scrollPane = new JScrollPane(jep);
f.setContentPane(scrollPane);
} catch (IOException ex) {
f.getContentPane().add(new Label("Could not load http://www.oreilly.com"));
}
使用这种构造函数时,不需要调用
超级会员免费看
订阅专栏 解锁全文
66

被折叠的 条评论
为什么被折叠?



