Can't remove extra line spacing in JTextPane for html content

后端 未结 3 1720
清歌不尽
清歌不尽 2021-01-25 05:11

I can\'t squeeze together the lines in a Java JTextPane if I set the content-type to text/html. I would like them as close together as they are when th

相关标签:
3条回答
  • 2021-01-25 05:32

    Solved! If I use Courier New instead of monospace for the font-family, the line spacing is exactly the same as in the text-plain version under Windows. Thanks everyone!

    0 讨论(0)
  • 2021-01-25 05:38

    This may be platform dependent:

    0 讨论(0)
  • 2021-01-25 05:49

    Try something like this

    StyledDocument doc= textPane.getStyledDocument();
    MutableAttributeSet attr= new SimpleAttributeSet();
    StyleConstants.setLineSpacing(attr, -0.2f); //NOTE: negative value.
    

    Looks like you are running windows. What version of JDK/JRE is in use?

    0 讨论(0)
提交回复
热议问题