如何修改JTextPane中的字母间距? [英] How to modify letter-spacing in a JTextPane?

查看:183
本文介绍了如何修改JTextPane中的字母间距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要修改JTextPane中的字母间距(字体跟踪),并且我无法使它工作。



当我使用一个JTextArea,我可以这样做:

  Font font = new Font(Courier New,Font.PLAIN,10); 
HashMap< TextAttribute,Object> attrs = new HashMap< TextAttribute,Object>();
attrs.put(TextAttribute.TRACKING,-0.1);
font = font.deriveFont(attrs);
textArea.setFont(font);

但是由于我需要更改行距,我需要使用JTextPane, p>

  textPane.setFont(font)

与JTextArea一样无效。我试过的另一件事是:
$ b $ pre $ MutableAttributeSet set = new SimpleAttributeSet();
StyleConstants.setLineSpacing(set,-0.2);
StyleConstants.setFontFamily(set,Courier New);
StyleConstants.setFontSize(set,10);
set.addAttribute(TextAttribute.TRACKING,-0.1);
ta.setParagraphAttributes(set,true);

但是跟踪属性不起作用。

你是指kerning吗?这一个显示如何指定自定义字距和一些更多的文字效果
http:// java-sl。 com / gp_effects.html


I'm need to modify letter-spacing (font tracking) in a JTextPane, and I can't get it to work.

When I'm using a JTextArea, I can just do:

Font font = new Font("Courier New", Font.PLAIN, 10);
HashMap <TextAttribute, Object> attrs = new HashMap<TextAttribute, Object>();
attrs.put(TextAttribute.TRACKING, -0.1);
font = font.deriveFont(attrs);
textArea.setFont(font);

but as I need to change line spacing, I need to use a JTextPane, and doing:

textPane.setFont(font)

as I did with the JTextArea doesn't work. another thing I tried was:

MutableAttributeSet set = new SimpleAttributeSet();
StyleConstants.setLineSpacing(set, -0.2);
StyleConstants.setFontFamily(set,"Courier New");
StyleConstants.setFontSize(set, 10);
set.addAttribute(TextAttribute.TRACKING, -0.1);
ta.setParagraphAttributes(set, true);

But the tracking attribute doesn't work.

What am I doing wrong?

解决方案

Do you mean kerning? This one shows how to specify custom kerning and some more text effect http://java-sl.com/gp_effects.html

这篇关于如何修改JTextPane中的字母间距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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