我想打印出 JEditorPane 的内容,其中包含突出显示的文本(颜色是使用 setCharacterAttributes 设置的)。但是,当我使用最基本的 print() 方法时,如下所示:
try {
boolean complete = TextArea.print();
if (complete) {
return;
}
else {
JOptionPane.showMessageDialog(null, "File could not be printed");
}
}
catch (PrinterException ex) {
JOptionPane.showMessageDialog(null, "File could not be printed");
}
打印的文档看起来不符合我的预期。具体来说:
- 打印区域的背景(而非边距)为浅蓝色。
- 突出显示的文本以彩色打印。
- 字体很大(每行只有 6 或 7 个字)。这是在创建 JEditorPane 时指定的 - 打印时有没有办法使用其他尺寸?
我想要的是白色背景上的黑色文本。如果有人能指出我正确的方向,我将非常感激!
最佳答案
你可以试试这个http://java-sl.com/JEditorPanePrinter.html打印 JEditorPane 的内容。
不打印突出显示。它不是属性的一部分。要打印文本背景/前景,您应该指定文本元素的属性。
要缩放 JEditorPane 的内容,您可以尝试此 http://java-sl.com/Scale_In_JEditorPane.html
要查看背景,只需设置 JEditorPane 的背景。但是,某些编辑器工具包对 Root View 使用自己的渲染,您可能需要在 Root View 中指定颜色。
关于java - 打印 jeditorpane 时控制字体大小和背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20682311/