gpt4 book ai didi

java - 如何修改 JTextPane 中的字母间距?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:56:45 25 4
gpt4 key购买 nike

我需要修改 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,并执行以下操作:

textPane.setFont(font)

正如我对 JTextArea 所做的那样,它不起作用。我尝试的另一件事是:

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);

但是跟踪属性不起作用。

我做错了什么?

最佳答案

你是说字距调整吗?这个展示了如何指定自定义字距调整和更多文本效果 http://java-sl.com/gp_effects.html

关于java - 如何修改 JTextPane 中的字母间距?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5673281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com