1

基本上我有一个名为 FlowLayout.html 的文件,我想将它读入 JEditorPane。到目前为止,我拥有所有代码,但我不知道如何在窗格中打开文件。

  JEditorPane jtfInfo = new JEditorPane();
  jtfInfo.setEditable(false);
  p3.add(jtfInfo);

  public void getFlowLayout(){
    jftInfo.setContentType("text/html");
  //I dont know this step and setContentType gives me an error in netbeans Cannot find symbol

}

4

1 回答 1

3

您可以setPage()使用指向 FlowLayout.html 文件的 URL 调用该方法:

public void getFlowLayout(){
    jftInfo.setPage(new URL("path to file"));
}

来自Java 教程:如何使用编辑器窗格和文本窗格

“setPage 方法打开 URL 指向的资源并计算出文本的格式(在示例中为 HTML)。如果文本格式已知,编​​辑器窗格将使用在 URL 中找到的文本进行初始化。A “

于 2012-04-17T00:58:01.767 回答