Java 绝地武士窗格的打印

Java 绝地武士窗格的打印,java,swing,printing,awt,jeditorpane,Java,Swing,Printing,Awt,Jeditorpane,在swing中,我有一个带有JScrollPane的组件JEditorPane,我想打印JEditorPane的内容。我应该可以灵活地在运行时更改打印页面的标题。我正在使用以下代码,但它不起作用 try{ JEditorPane editorpane1= new JEditorPane(); editorpane1.setContentType("text/html"); editorpane1.setEditable(false); File file1= new File(

在swing中,我有一个带有JScrollPane的组件JEditorPane,我想打印JEditorPane的内容。我应该可以灵活地在运行时更改打印页面的标题。我正在使用以下代码,但它不起作用

 try{
  JEditorPane editorpane1= new JEditorPane();
  editorpane1.setContentType("text/html");
  editorpane1.setEditable(false);
  File file1= new File("path of the html file");
  URL url= new URL(file1);
  editorpane1.setPage(url);
  JScrollPane jsp= new JScrollPane(editorpane1);
  editorpane1.print();
  }
 catch(Exception ex)
 {

  }

您可以使用编辑器套件独立打印机


要添加页眉,只需修改根视图的paint()方法即可添加上面的内容。

您可以使用编辑器工具包独立打印机


要添加页眉,只需修改根视图的paint()方法即可添加上面的内容。

打印到文件或打印机打印到文件或打印机