我无法从JTextPane
. 这甚至可能吗?
谷歌向我展示了以下代码片段,但它似乎对我
JTextPane
的 .
SimpleAttributeSet sas = new SimpleAttributeSet();
StyleConstants.setLineSpacing(sas , 0.0f);
textPane.setParagraphAttributes(sas , false);
我目前已将JTextPane
's 字体设置为“Consolas”,字体大小为 9。我正在尝试正确显示某些 ASCII 艺术(就像DAMN NFO VIEWER一样)。
这就是它在我的 GUI 中的样子JTextPane
以及我希望它的样子:
这就是 DAMN NFO VIEWER 显示相同 ASCII 艺术的方式(正确的方式)。
我试过使用与 DAMN NFO VIEWER 相同的字体和大小,但这并没有消除差距,所以我想我必须做一些其他的改变。任何建议表示赞赏。
编辑
这是我尝试应用的方法SimpleAttributeSet()
,也许我做得不对:
nfoFileTextPane = new javax.swing.JTextPane();
StyledDocument doc = nfoFileTextPane.getStyledDocument();
Element e = doc.getParagraphElement(0);
MutableAttributeSet mas = new SimpleAttributeSet();
StyleConstants.setLineSpacing(mas, -0.2f);
StyleConstants.setSpaceAbove(mas, -0.2f);
StyleConstants.setSpaceBelow(mas, -0.2f);
//0-1000 test
doc.setParagraphAttributes(0, 1000, mas, true);