如何在JtextPane中设置行距? [英] How to set the line spacing in a JtextPane?

查看:179
本文介绍了如何在JtextPane中设置行距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我像这样设置JTextPane:

First of all, i set the JTextPane like this:

HTMLEditorKit editorKit = new HTMLEditorKit();
HTMLDocument document = (HTMLDocument) editorKit.createDefaultDocument();
JTextPane textPane = new JTextPane();
textPane.setContentType("text/html");
textPane.setDocument(document);

我想在JtextPane中设置行距,这是我的想法,但是它不起作用:

and i want to set the line spacing in the JtextPane , this is my idea,but it can't work:

SimpleAttributeSet aSet = new SimpleAttributeSet();
StyleConstants.setLineSpacing(aSet, 50);
textPane.setParagraphAttributes(aSet, false);

我错了吗?

推荐答案

要设置JTextPane的样式,您可以使用样式表:

To style JTextPane you could use Stylesheets: Look for HtmlEditorKit#setStyleSheet

StyleSheet sh = editorKit.getStyleSheet();
sh.addRule("body {line-height: 50px}");

这篇关于如何在JtextPane中设置行距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆