JEditorPane 显示HTML文件 JEditorPane如何显示本地的HTML文件,希望给个例子,谢谢!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给楼主给例子,这个肯定可以用import java.awt.Dimension;import java.awt.Rectangle;import java.awt.Toolkit;import java.io.File;import java.io.IOException;import java.net.MalformedURLException;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JEditorPane;public class IndexPanel extends JPanel{ private static final long serialVersionUID = 1L; private JLabel jLabel24 = null; private JEditorPane editorPane = null; private JScrollPane scrollPane = null; /** * This is the default constructor */ public IndexPanel() { super(); initialize(); } /** * This method initializes this * * @return void */ private void initialize() { this.setLayout(null); this.setSize(new Dimension(610, 660)); this.add(getJLabel24(), null); this.add(getScrollPane(), null); } /** * This method initializes indexPanel * * @return javax.swing.JPanel */ private JLabel getJLabel24() { if (jLabel24 == null) { jLabel24 = new JLabel(); jLabel24.setText("目录和索引"); jLabel24.setBounds(new Rectangle(207, 16, 202, 18)); } return jLabel24; } /** * This method initializes editorPane * * @return javax.swing.JEditorPane */ private JEditorPane getEditorPane() { if (editorPane == null) { editorPane = new JEditorPane(); editorPane.setEditable(false); editorPane.setContentType("text/html"); File file = new File( ".\\resources\\光盘使用说明.htm"); String strURL = file.getAbsolutePath(); strURL = "file:" + strURL; try { editorPane.setPage(strURL); } catch (MalformedURLException e) { // TODO Auto-generated catch block System.err.println(e.toString()); System.exit(1); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return editorPane; } /** * This method initializes scrollPane * * @return javax.swing.JScrollPane */ private JScrollPane getScrollPane() { if (scrollPane == null) { scrollPane = new JScrollPane(); scrollPane.setBounds(new Rectangle(4, 47, 622, 659)); scrollPane.setViewportView(getEditorPane()); } return scrollPane; }} 一个小题。大牛给看一下。 将文件路径作为参数时(String类型),编译提示非法转义字符 请问如何 用 java 开发 asterisk 的 agi 接口程序 ? 哪里有教程 ? 是不是需要有 开发包? String 如何转换成 ArrayList? getResource返回的文件路径含有"%e9%a1%b9%e7%9b%ae",如何读取啊? 求助!关于抽象类! tomcat的配置问题,弄了很久了,大家帮帮我 关于JBUILDER中的图标问题 帮忙,要个密码,谢谢 学以至用,请帮忙! 求救!java rmi 启动出错 画出贝塞尔曲线,怎么取x坐标对应的y坐标?
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JEditorPane;public class IndexPanel extends JPanel
{ private static final long serialVersionUID = 1L; private JLabel jLabel24 = null; private JEditorPane editorPane = null; private JScrollPane scrollPane = null; /**
* This is the default constructor
*/
public IndexPanel()
{
super();
initialize();
} /**
* This method initializes this
*
* @return void
*/
private void initialize()
{ this.setLayout(null);
this.setSize(new Dimension(610, 660)); this.add(getJLabel24(), null);
this.add(getScrollPane(), null);
} /**
* This method initializes indexPanel
*
* @return javax.swing.JPanel
*/
private JLabel getJLabel24()
{
if (jLabel24 == null)
{
jLabel24 = new JLabel();
jLabel24.setText("目录和索引");
jLabel24.setBounds(new Rectangle(207, 16, 202, 18));
}
return jLabel24;
} /**
* This method initializes editorPane
*
* @return javax.swing.JEditorPane
*/
private JEditorPane getEditorPane()
{
if (editorPane == null)
{
editorPane = new JEditorPane();
editorPane.setEditable(false);
editorPane.setContentType("text/html");
File file = new File(
".\\resources\\光盘使用说明.htm"); String strURL = file.getAbsolutePath();
strURL = "file:" + strURL; try
{
editorPane.setPage(strURL);
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
System.err.println(e.toString());
System.exit(1);
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return editorPane;
} /**
* This method initializes scrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getScrollPane()
{
if (scrollPane == null)
{
scrollPane = new JScrollPane();
scrollPane.setBounds(new Rectangle(4, 47, 622, 659));
scrollPane.setViewportView(getEditorPane());
}
return scrollPane;
}}