使用JFrame
和拆分窗格来显示两个大内容之间的区别。它显示了差异并着色了差异。所以它看起来像一张有着不同颜色的桌子。可以将它保存为HTML文件吗?Swing JFrame内容保存到html文件
JEditorPane
和HTMLEditorKit
仅使用文本内容将其保存在文件中。是否需要手动完成差异并在HTML中重新着色?
有没有办法将表格内容从Swing复制到HTML?
私人无效saveToHTML(文件selectedFile){
ConfigurationDiffUtil util = new ConfigurationDiffUtil(previous.getRuRO().getContent(), latest.getRuRO().getContent());
JEditorPane yourEditorPane = new JEditorPane();
yourEditorPane.setContentType("text/html");
yourEditorPane.setText(util.getLeftEditor().getText());
if (selectedFile.isDirectory()) {
String deviceFolderName = selectedFile.getPath() + File.separator + escapeFileName(deviceId.getName());
File deviceFolder = new File(deviceFolderName);
if ((deviceFolder.exists() && confirmOverwrite(deviceFolderName)) || deviceFolder.mkdir()) {
String saveFileName = escapeFileName(deviceId.getName())+"."+ "html";
File dataFile = new File (deviceFolder, saveFileName);
try {
BufferedWriter out = new BufferedWriter(new FileWriter(dataFile));
HTMLWriter hw = new HTMLWriter(out, (HTMLDocument) yourEditorPane.getDocument());
hw.write();
out.flush();
out.close();
} catch (FileNotFoundException e) {
Log.error(this, "ExportCredentials:credentials file not found",e);
} catch (BadLocationException e) {
Log.error(this, "ExportCredentials:credentials file not found",e);
}
catch (IOException e) {
Log.error(this, "ExportCredentials:unable to read the file",e);
}
}
}
}
现在我已经创造了这个代码段。在这里,我设置了左侧窗格的内容。 yourEditorPane.setText(util.getLeftEditor()。getText());
它将它保存在一个html文件中。
在这里,我只能保存html中的文本。摇摆的外观和感觉(表格中的左右内容并显示高光差异),无法通过HTML获取。只有文字可以保存为HTML?
*“它显示差异并着色差异。”*如何?请注意,颜色(针对差异)可能会呈现为HTML。 'JEditorPane'和'JTextPane'支持(简单的)HTML渲染。 –
为了更好地提供帮助,请发布[MCVE](http://stackoverflow.com/help/mcve)。 –
我有java代码来计算差异并绘制颜色。所以JFrame包含带有颜色差异的分割面板。现在我想将它保存到一个完全相同内容的html文件中。 – user1631072