java高手请进 如何在窗体中嵌入网页?

srss008 2007-12-03 10:15:40
需要在窗体里嵌入网页,有这样的控件吗?小弟实在没分,多包涵,先谢过!
...全文
260 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
srss008 2007-12-04
  • 打赏
  • 举报
回复
不行啊,超链接能显示出来,可是按钮不能显示。只显示‘>’个。


窗体源代码:
package Frame;

import java.awt.Color;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import javax.swing.*;

public class FrameOne extends JFrame {
public FrameOne() throws IOException{
JEditorPane EditorPane= new JEditorPane();
URL url = this.getClass().getResource("/Frame/help.html");
EditorPane.setEditable(false);
EditorPane.setPage(url);
this.add(EditorPane);
}
}
HTML源代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>Index page!!!!</title>
</head>
<body>
<table width="200" border="1" align="center">
<tr>
<td align="center"><input type="button" value="请点击"/></td>
</tr>
<tr>
<td align="center"><input type="button" value="请点击"/></td>
</tr>
<tr>
<td align="center"><input type="button" value="请点击"/></td>
</tr>
</table>
<p><a href="test.html">111111111111</a></p>
</body>
</html>

主函数源代码:
package Main;

import java.io.IOException;
import Frame.FrameOne;

public class MainTest {
public static void main(String[] args) throws IOException {
FrameOne fo = new FrameOne();
fo.setSize(new Dimension(800,600));
fo.setVisible(true);
}
}

结果:


chenweionline 2007-12-04
  • 打赏
  • 举报
回复
可以的,JEditorPane只支持html和rtf,可以用来浏览简单的html文档
srss008 2007-12-04
  • 打赏
  • 举报
回复
请教2楼大哥
那在html里的超链接和其它的按钮等功能是不是也能实现啊?
nj_dobetter 2007-12-04
  • 打赏
  • 举报
回复
没错,JEditorPane可以。
也可以用JNI内嵌一个IE浏览器,不过这会破坏Java程序移植性,除非只在Windows上运行。
chenweionline 2007-12-03
  • 打赏
  • 举报
回复
JEditorPane可以用来加载html
phyeas 2007-12-03
  • 打赏
  • 举报
回复
Applet试过了没

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧